Announcement

Collapse
No announcement yet.

Problem: Text only writing on screen for last two trade signals

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

  • Problem: Text only writing on screen for last two trade signals

    Hi,

    I have written a simple trading system that when certain indicators kick in together, a square is drawn on the screen indicating to go long or short.

    I have also created a simple signal strength indicator in another file that tells me how strong the signal is.

    What I want to do is get the signal strength to print over the square on the screen. I have written (below) what i think it should be however it only shows the strength on the last two signals.

    Any help would be much appreciated:

    (code for trade signals)

    var fpArray = new Array();
    var bInit = false;
    var xRSI = null;
    var xStoch = null;
    var xMACD = null;
    var SSB = null;
    var SSS = null;

    var vLastAlert = -1;
    var i=0;
    var j=0;

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("Daily Dot");
    setColorPriceBars(true);
    setComputeOnClose(true);
    setDefaultPriceBarColor(Color.black);
    setShowTitleParameters(false);
    setCursorLabelName("Daily Strategy",0);
    var x =0;
    fpArray[x] = new FunctionParameter("RSILength",FunctionParameter.NU MBER);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(30);

    }
    fpArray[x] = new FunctionParameter("Stoch1",FunctionParameter.NUMBE R);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(26);
    }
    fpArray[x] = new FunctionParameter("Stoch2",FunctionParameter.NUMBE R);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(9);
    }
    fpArray[x] = new FunctionParameter("Stoch3",FunctionParameter.NUMBE R);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(3);
    }
    fpArray[x] = new FunctionParameter("MACD1",FunctionParameter.NUMBER );
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(26);
    }
    fpArray[x] = new FunctionParameter("MACD2",FunctionParameter.NUMBER );
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(52);
    }
    fpArray[x] = new FunctionParameter("MACD3",FunctionParameter.NUMBER );
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(9);
    }
    fpArray[x] = new FunctionParameter("RSIUPPER",FunctionParameter.NUM BER);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(40);
    }
    fpArray[x] = new FunctionParameter("RSILOWER",FunctionParameter.NUM BER);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(60);
    }


    }

    function main(RSILength,Stoch1,Stoch2,Stoch3,MACD1,MACD2,MA CD3,RSIUPPER,RSILOWER) {
    var nBarState = getBarState();
    if (nBarState == BARSTATE_ALLBARS) { //BARSTATE_ALLBARS I think is the first bar on the screen
    if (RSILength == null) RSILength = 30;
    if (Stoch1 == null) Stoch1 = 26;
    if (Stoch2 == null) Stoch2 = 9;
    if (Stoch3 == null) Stoch3 = 3;
    if (MACD1 == null) MACD1 = 26;
    if (MACD2 == null) MACD2 = 52;
    if (MACD3 == null) MACD3 = 9;
    if (RSILOWER == null) RSILOWER = 40;
    if (RSIUPPER == null) RSIUPPER = 60;


    }

    if (bInit == false) {
    xRSI = rsi(RSILength);
    xStoch = new StochStudy(Stoch1,Stoch2,Stoch3);
    xMACD = new MACDStudy(MACD1, MACD2, MACD3, "Close", false);
    SSB = efsExternal("ESSB.efs");
    SSS = efsExternal("ESSS.efs");
    bInit = true;
    }

    if(getCurrentBarIndex() == 0) return;
    if(xRSI.getValue(0) == null) return;
    if(xStoch.getValue(0) == null) return;
    if(xMACD.getValue(0) == null) return;
    if(SSB.getValue(0) == null) return;
    if(SSS.getValue(0) == null) return;



    for ( i =0 ; i >= -25 ; i-- ) {
    for ( j=0 ; j >= -30 ; j-- ) {

    if (
    xStoch.getValue(StochStudy.FAST,i) > xStoch.getValue(StochStudy.SLOW,i) &&
    xStoch.getValue(StochStudy.FAST,i-1) < xStoch.getValue(StochStudy.SLOW,i-1) &&


    xMACD.getValue(MACDStudy.HIST,j) > 0 &&
    xMACD.getValue(MACDStudy.HIST,j-1) < 0 &&
    xRSI.getValue(0) > RSILOWER

    )
    onAction1()


    else if (
    xStoch.getValue(StochStudy.FAST,i) < xStoch.getValue(StochStudy.SLOW,i) &&
    xStoch.getValue(StochStudy.FAST,i-1) > xStoch.getValue(StochStudy.SLOW,i-1) &&

    xMACD.getValue(MACDStudy.HIST,j) < 0 &&
    xMACD.getValue(MACDStudy.HIST,j-1) > 0 &&
    xRSI.getValue(0) < RSIUPPER

    )
    onAction2()
    }};
    /*if(Strategy.isLong())
    setPriceBarColor(Color.green);
    else if(Strategy.isShort())
    setPriceBarColor(Color.red);*/



    return /*vLastAlert*/;


    }

    function postMain() {

    }



    function onAction1() {
    if (Strategy.isLong() == false) {
    Strategy.doLong("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    debugPrintln("Buy" + "//" + getSymbol() + "//" + "close = " + close() + "//" );
    drawShapeRelative(0, low() - (low()-low()*0.99), Shape.SQUARE, "", Color.RGB(0,0,255), Shape.LEFT);
    //Alert.playSound("train.wav");
    Alert.addToList(getSymbol(),"Buy=" + getSymbol() + "@" + close(), Color.black, Color.green );

    debugPrintln("Buy Strength:" +" "+ Math.round(SSB.getValue(0)/3) + "%");

    debugPrintln();
    drawTextRelative(0, low() - (low()-low()*0.98), Math.round(SSB.getValue(0)/3) + "%", Color.blue, null,
    Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Buy Strength");

    vLastAlert = 1;
    }}
    function onAction2() {
    if (Strategy.isShort() == false) {
    Strategy.doShort("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() + (high()-high()*0.99), Shape.SQUARE, "", Color.RGB(255,0,0), Shape.LEFT);
    debugPrintln( "Sell" + "//" + getSymbol() + "//" + "close = " + close() + "//" );

    debugPrintln("Sell Strength:" +" "+ Math.round(SSS.getValue(0)/3) + "%");
    debugPrintln();
    drawTextRelative(0, high() + (high()-high()*0.98), Math.round(SSS.getValue(0)/3) + "%", Color.red, null,
    Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Sell Strength");
    //Alert.playSound("train.wav");
    Alert.addToList(getSymbol(),"Sell=" + getSymbol() + "@" + close(), Color.black, Color.red);
    vLastAlert = -1;
    }}

  • #2
    Here is a simplified version of my problem:

    I have a piece of code that generates trade signals when certain indicators kick in. These criteria are defined in the function main().

    When met, the program goes outisde the main to "onAction1()" to see what it has to do. One of the criteria here refers to an efsExternal function.

    function main(){
    var SSB = efsExternal("SSB.efs")
    if (RSI > 50) onAction1();
    }

    //outisde main
    function onAction1() {
    drawTextRelative(0, low() - (low()-low()*0.98), Math.round(getSeries(SSB)/3) + "%", Color.blue, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Buy Strength");

    The getSeries part is the EFS external function called SSB).

    Now, this should write text on the bar that I get my signal and it does for the last signal but not for the ones previous.

    Below is a picture to illustrate this.

    Any help would be much appreciated.
    Attached Files

    Comment


    • #3
      DolmenProp
      That is happening because the tagID parameter you are using in each drawTextRelative() command is the same for all the graphic objects being drawn by that command and since there can only be one graphic object per tagID only the most recent one is drawn on the chart [the other ones are removed]. You need to use a tagID that will be unique to each graphic object you want to draw
      If you run a search in this forum you will find many examples of how to do this as the subject has been covered before
      Alex


      Originally posted by DolmenProp
      Here is a simplified version of my problem:

      I have a piece of code that generates trade signals when certain indicators kick in. These criteria are defined in the function main().

      When met, the program goes outisde the main to "onAction1()" to see what it has to do. One of the criteria here refers to an efsExternal function.

      function main(){
      var SSB = efsExternal("SSB.efs")
      if (RSI > 50) onAction1();
      }

      //outisde main
      function onAction1() {
      drawTextRelative(0, low() - (low()-low()*0.98), Math.round(getSeries(SSB)/3) + "%", Color.blue, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Buy Strength");

      The getSeries part is the EFS external function called SSB).

      Now, this should write text on the bar that I get my signal and it does for the last signal but not for the ones previous.

      Below is a picture to illustrate this.

      Any help would be much appreciated.

      Comment

      Working...
      X