Announcement

Collapse
No announcement yet.

Multiple arrows per signal

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple arrows per signal

    Hi

    Can someone please tell me what I'm doing wrong?

    I have written an efs that marks an arrow when MA1 > MA2 & > PtY

    I only want this to happen the first instance that this is true, not every time

    I have managed to get it to work at MA crossover's but the same formula does not seem to work?

    See efs below

    Cheers all

    var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var vSMA15 = new MAStudy(15, 0, "Close", MAStudy.SIMPLE);
    var vUpTrend = null;
    var vDownTrend = null;
    var vLastAlert = -1;
    var vValue = -1;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Print Value 2");
    setCursorLabelName("5MA", 0);
    setCursorLabelName("15MA", 1);
    setCursorLabelName("Target1", 2);
    setCursorLabelName("Target2", 3);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarFgColor(Color.maroon, 0);
    setDefaultBarFgColor(Color.red, 2);
    setDefaultBarFgColor(Color.teal, 1);
    setDefaultBarFgColor(Color.lime, 3);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    setPlotType(PLOTTYPE_FLATLINES, 2);
    setDefaultBarFgColor(Color.red, 3);
    setComputeOnClose(true)
    }

    debugClear()
    function main() {
    if (

    myVar = sma( 5 ));
    x = myVar + 2.5;
    y = myVar -2.5;

    {if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && (vValue != 1))
    onAction3()}

    {if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && (vValue != 2))
    onAction4()}

    {if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) < vDownTrend &&
    (vLastAlert != 1)) drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.blue, Shape.BOTTOM);
    vLastAlert = 1}

    {if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) > vUpTrend &&
    (vLastAlert != 2)) drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.purple, Shape.TOP);
    vLastAlert = 2}

    return new Array(
    vSMA5.getValue(MAStudy.MA),
    vSMA15.getValue(MAStudy.MA)
    );
    }

    //{{Action_3
    function onAction3() {
    drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.BOTTOM);
    debugPrintln("y= " + y);
    drawLineRelative(0, (y), +25, (y), PS_SOLID, 2, Color.red, getValue("RawTime") + "xdownpt");
    vDownTrend = y; debugPrintln("DownTrend = " + vDownTrend);
    vValue = 1;
    }
    //}}Action_3

    //{{Action_4
    function onAction4() {
    drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.TOP);
    debugPrintln("x= " + x);
    drawLineRelative(0, (x), +25, (x), PS_SOLID, 2, Color.green, getValue("RawTime") + "xuppt");
    vUpTrend = x; debugPrintln("UpTrend = " + vUpTrend);
    vValue = 2;}
    //{{Action_4

  • #2
    Try this (and review the changes I made to your logic statements)..

    There was also an issue with your use of variables. Global variables need to be initiated above "main" and "premain". Then they can be used anywhere in your code (below).

    You also may have a logic issue with your control of UPTREND and DOWNTREND. Right now, you have your code setup to only allow the secondary triggers to go off when the MA is above/below these values. Well, if you don't reset them with another set of logic, then it will only allow buying higher levels or selling lower levels.

    Anyway, this should help you understand how to structure the program (any efs). You want to use the { and } to enclose functions, if, for and many other statements. You had those all messed up in your original. It may help you to look at other sample code when you get stuck.

    PHP Code:


    var vSMA5 = new MAStudy(50"Close"MAStudy.SIMPLE);
    var 
    vSMA15 = new MAStudy(150"Close"MAStudy.SIMPLE);
    var 
    vUpTrend 0;
    var 
    vDownTrend 99999999999;
    var 
    vLastAlert = -1;
    var 
    vValue 0;
    var 
    x;
    var 
    y;

    function 
    preMain() {
    setPriceStudy(true);
    setStudyTitle("Print Value 2");
    setCursorLabelName("5MA"0);
    setCursorLabelName("15MA"1);
    setCursorLabelName("Target1"2);
    setCursorLabelName("Target2"3);
    setDefaultBarStyle(PS_SOLID0);
    setDefaultBarStyle(PS_SOLID1);
    setDefaultBarFgColor(Color.maroon0);
    setDefaultBarFgColor(Color.red2);
    setDefaultBarFgColor(Color.teal1);
    setDefaultBarFgColor(Color.lime3);
    setDefaultBarThickness(20);
    setDefaultBarThickness(21);
    setPlotType(PLOTTYPE_LINE0);
    setPlotType(PLOTTYPE_LINE1);
    setPlotType(PLOTTYPE_FLATLINES2);
    setDefaultBarFgColor(Color.red3);
    setComputeOnClose(true)
    }

    debugClear()
    function 
    main() { 

    var 
    myVar sma)); 
    myVar 2.5;
    myVar -2.5

    if (
    vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && (vValue <= 0))  {
      
    onAction3();
    }

    if (
    vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && (vValue >= 0)) {
       
    onAction4();
    }

    if (
    vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) < vDownTrend &&
    (
    vLastAlert != 1)) {
       
    drawShapeRelative(0high(-2), Shape.DOWNARROW""Color.blueShape.BOTTOM); 
       
    vLastAlert 1;
    }

    if (
    vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) > vUpTrend &&
    (
    vLastAlert != 2)) {
       
    drawShapeRelative(0low(-2), Shape.UPARROW""Color.purpleShape.TOP); 
       
    vLastAlert 2;
    }

    return new Array(
    vSMA5.getValue(MAStudy.MA),
    vSMA15.getValue(MAStudy.MA)
    );
    }

    //{{Action_3
    function onAction3() {
    drawShapeRelative(0high(-2), Shape.DOWNARROW""Color.RGB(255,0,0), Shape.BOTTOM); 
    debugPrintln("y= " y);
    drawLineRelative(0, (y), +25, (y), PS_SOLID2Color.redgetValue("RawTime") + "xdownpt");
    vDownTrend y
    debugPrintln("DownTrend = " vDownTrend);
    vValue 1;
    }
    //}}Action_3

    //{{Action_4
    function onAction4() {
    drawShapeRelative(0low(-2), Shape.UPARROW""Color.RGB(0,255,0), Shape.TOP);
    debugPrintln("x= " x);
    drawLineRelative(0, (x), +25, (x), PS_SOLID2Color.greengetValue("RawTime") + "xuppt");
    vUpTrend x
    debugPrintln("UpTrend = " vUpTrend);
    vValue = -1;
    }
    //{{Action_4 
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      This is great,

      Thanks for all your help, and tips

      Comment

      Working...
      X