Announcement

Collapse
No announcement yet.

Tradesignal at startup when there shouldn't be one

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

  • Tradesignal at startup when there shouldn't be one

    When an EFS study gets loaded into the chart at startup, or when I manually reload them, a tradesignal gets sent to a DLL I have loaded into the study when there shouldn't be a tradesignal. Is there a reason the study does this and what can I do to prevent this?

  • #2
    kimosabe
    You need to enclose your trading signals inside an if(getCurrentBarIndex()==0) statement (or -1 if running setComputeOnClose()) to ensure that they are processed only on the current bar in real time
    Alex

    Comment


    • #3
      I'm using setComputeOnClose(true) and when I do this;

      if(getCurrentBarIndex()==-1) {
      tradesignal
      }

      I get a tradesignal at startup and when I reload the strategy. But when I use setComputeOnClose(true) and this;

      if(getCurrentBarIndex()==0)
      tradesignal
      }

      I don't get a tradesignal at startup or reload. Is this the way it's supposed to be?

      Comment


      • #4
        This is how I have it set up so I don't get a tradesignal at startup:

        setComputeOnClose(true);

        if(getCurrentBarIndex()==0){
        condition is true
        tradesignal
        }


        But, I don't get a signal when I'm supposed to now.

        Comment


        • #5
          This is the way I configured it:

          preMain();
          setComputeOnClose(true);

          main()


          condition is true
          if(getCurrentBarIndex()==-1(){

          tradesignal
          }

          I get a sound alert at startup but no tradesignal sent to the DLL.
          Before, when I didn't have the if(getCurrentBarIndex()==-1() in the code, I got a tradesignal sent to the DLL at startup but no sound alert. That's weird, but I did it the way you said Alexis and it's working good right now. Thanks for the help.

          Comment


          • #6
            kimosabe
            Glad to hear that it is working now.
            The reason why if(getCurrentBarIndex()==0) will not trigger any events with setComputeOnClose() is that bar index 0 is never processed. The most current bar being processed in that case is bar index -1.
            As to the alerts if you do not want them to trigger while the efs is being loaded then include them inside the if(getCurrentBarIndex()==0) statement (or -1 if using setComputeOnClose())
            Alex

            Comment


            • #7
              I'm still having a problem with tradesignals on initial startup. This is what I have:

              preMain();
              setComputeOnClose(true);

              main()


              if(condition is true){
              if(getCurrentBarIndex()==-1){
              audio alert
              tradesignal to DLL
              }
              }


              When I first start the program I get a tradesignal to DLL and audio alert. Afterward when I reload the study, I just get an audio alert. I knew this was strange that I got the audio alert but not the tradesignal on reload.

              This is far from resolved since all configurations I try I still get the tradesignals on startup. The condition isn't really true at the bar at startup. It must read back to find the last true condition and send the signal. Any possible way to correct this?
              Last edited by kimosabe; 04-21-2005, 02:25 PM.

              Comment


              • #8
                Possible Solution..

                What sounds like is happening is...

                your code is identifying a trading signal before it reaches the most recent bar.. Then, when it gets to the most recent bar, it fires off a trade signal that is not correct..

                Here is what I would do to fix it...

                PHP Code:
                preMain();
                setComputeOnClose(true); 

                main()

                if(
                getCurrentBarIndex()==-1){
                    if(
                condition is true for SELL signal){
                     
                audio alert
                     tradesignal to DLL SELL
                   
                }
                    if(
                condition is true for BUY signal){
                     
                audio alert
                     tradesignal to DLL BUY
                   
                }

                This way, your code will not test for any new signals till it reaches the most recent bar - thus (I hope) solving your problem.

                If your code is more complex than this (*ie: setting triggers from past price bars and carrying those triggers to the current bar)... then we'll need to address these issues in a different manner.

                B
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment


                • #9
                  oops - one more thing..

                  PHP Code:

                  //  You probably need control variables to track the condition of your code.
                   
                  var StrategyisLong false;
                   var 
                  StrategyisShort false;

                  preMain();
                  setComputeOnClose(true); 

                  main()

                   
                  // 

                  if(getCurrentBarIndex()==-1){
                    if ((
                  condition is true for SELL signal) && (!StrategyisShort)) {
                     
                  audio alert
                     tradesignal to DLL SELL
                     StrategyisShort 
                  true;
                    }
                    if(
                  condition is true for BUY signal) && (!StrategyisLong)){
                      
                  audio alert
                      tradesignal to DLL BUY
                      StrategyisLong 
                  true;
                    }


                  This will prevent multiple trading signals..

                  B
                  Brad Matheny
                  eSignal Solution Provider since 2000

                  Comment


                  • #10
                    I put in the code you have but it didn't solve the problem. I'm not getting multiple signals, just one. It happens when I first start my trading software and then esignal. If I start eSignal first and then my software I don't get the signal until I reload the study. The first time I reload there is both the DLL signal and audio but thereafter I just get the audio alert when the study is reloaded.

                    Comment


                    • #11
                      kimosabe
                      The portion of code you posted is insufficient to replicate what is happening at your end.
                      At this point you need to post a functional example of your script (without the DLL portion) that reproduces the problem.
                      Alex

                      Comment


                      • #12
                        Ok, here is the code. It should give an audio alert every time you reload.




                        var fast = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);
                        var slow = new MAStudy(55, 0, "Close", MAStudy.SIMPLE);

                        var condition1;
                        var condition2;
                        var condition3;
                        var condition4;

                        function preMain() {
                        setPriceStudy(true);


                        setStudyTitle("MA1Min");
                        setComputeOnClose(true);

                        }

                        function main() {

                        var f = fast.getValue(MAStudy.MA);
                        var s = slow.getValue(MAStudy.MA);

                        if(f == null || s == null)
                        return;


                        if(f > s && getMostRecentTrade() > s)
                        condition1 = 1;

                        if(f < s && getMostRecentTrade() < s)
                        condition2 = -1;



                        if(getCurrentBarIndex() == -1) {


                        if((condition1 == 1) && (condition4 == -1)) {

                        condition4 = 0;

                        Alert.playSound( "c:\\program files\\eSignal\\Sounds\\pow.wav" );


                        }

                        if((condition2 == -1) && (condition3 == 1) ) {


                        condition3 = 0;

                        Alert.playSound( "c:\\program files\\eSignal\\Sounds\\pow.wav" );



                        }

                        }


                        if(f > s && getMostRecentTrade() > s)
                        condition3 = 1;

                        if(f < s && getMostRecentTrade() < s )
                        condition4 = -1;

                        condition1 = 0;
                        condition2 = 0;


                        return new Array(f,s);


                        }


                        Last edited by kimosabe; 04-23-2005, 05:58 AM.

                        Comment


                        • #13
                          kimosabe
                          Actually it does not always do that. Sometimes it does and sometimes it does not depending on the state of the conditions at the time of reload.
                          Insert the following debug line right below the first conditional statement ie below if(getCurrentBarIndex()==-1)

                          PHP Code:
                          debugPrintln("barIndex="+getCurrentBarIndex()+" cond1="+condition1+" cond2="+condition2+
                                  
                          " cond3="+condition3+" cond4="+condition4+" trade="+getMostRecentTrade()+" s="+s.toFixed(2)+
                                  
                          " long="+StrategyisLong+" short="+StrategyisShort); 
                          Then open the Formula Output Window and you should get a readout similar to the ones shown below.
                          In this first case upon reload the audio alert was triggered. Note in fact that the returned values match the conditions for the first set ie condition1 = 1 AND condition4 = -1 AND f > s (not shown because condition1 already includes that) AND getMostRecentTrade > s AND strategy false (or not true)



                          On this reload instead the alert was not triggered. The returned values in fact do not match either set of conditional statements because both conditions 1 AND 2 are 0.



                          So the alerts are being triggered correctly on the last processed bar as far as I can see.
                          Alex

                          Comment


                          • #14
                            Every time I reload this program I get an audio alert. First of all, looking at the formula output I can see it is reading condition3 and condition4 incorrectly.

                            if(f > s && getMostRecentTrade() > s)
                            condition3 = 1;

                            if(f < s && getMostRecentTrade() < s)
                            condition4 = -1;

                            At reload both these conditions can't be true but it's reading them both true every time. That's why it is giving the audio alert.

                            Comment


                            • #15
                              I think having 4 conditions was confusing the program so I simplified it to only have 2 conditions and it is working for now with no audio signals at reload. I will test it for a while and see how it works. Having use of the Formula Output window is very handy at debugging. Thanks for the help.

                              Comment

                              Working...
                              X