Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help with position handling

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

    Help with position handling

    Hi I am running a live strategy with position size of 50,000. However this am I noticed the strategy was long 100,000 despite EntryHandling =EntryHandling.UniqueEntries;

    this is the body of my strategy, does somebody know what I am doing wrong? why did It take a position twice?
    Code:
            #region Variables
    	private int tradeok = 1;
    	private double RngFrac = 0.35;
            #endregion
    
            protected override void Initialize()
            {	
            CalculateOnBarClose = true;
    	EntryHandling 	=	EntryHandling.UniqueEntries;
    	ExitOnClose = false;
    	}
            
      protected override void OnBarUpdate()
            {
    			//Enter long
    			if (CrossAbove(...)
    				&& tradeok == 1)
    			{
    				EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
    			}
    			
    			//Enter short
                if (CrossBelow(...)
    				&& tradeok == 1)
    			{
    				EnterShortLimit(Close[0] + RngFrac * (High[0] - Low[0]));
    			}
    			
    			// Exit short
    			if (Position.MarketPosition == MarketPosition.Short
    				&& CrossAbove(...)
    				&& tradeok == 1)
    			{
    				ExitShort();
    			}
    			
    			//Exit long
                if (Position.MarketPosition == MarketPosition.Long
    				&& CrossBelow(...)
    				&& tradeok == 1)
    			{
    				ExitLong();
    			}
    			
    			if (Position.MarketPosition == MarketPosition.Long
    				&& Time[0].DayOfWeek == DayOfWeek.Friday
    				&& ToTime(Time[0]) > ToTime(17, 59, 0))
                {
                    ExitLong();
                }
    
    
    			if (Position.MarketPosition == MarketPosition.Short
    				&& Time[0].DayOfWeek == DayOfWeek.Friday
    				&& ToTime(Time[0]) > ToTime(17, 59, 0))
                {
                    ExitShort();
                }
    		
    			if (Time[0].DayOfWeek == DayOfWeek.Sunday)
                {
                    tradeok = 0;
                }
    			
    			if (Time[0].DayOfWeek == DayOfWeek.Monday
    				&& ToTime(Time[0]) < ToTime(6, 0, 0))
                {
                    tradeok = 0;
                }
    
    			if (Time[0].DayOfWeek == DayOfWeek.Friday
    				&& ToTime(Time[0]) >= ToTime(15, 59, 0))
                {
                    tradeok = 0;
                }	
    			
    			else
    			{
    			tradeok = 1;
    			}
    			
            }
    NOTICE I've been running this strategy for months without any problem, over the week-end I have changed my entry long (and short) rule from:

    Code:
    //Enter long
    			if (CrossAbove(...)
    				&& tradeok == 1)
    			{
    				EnterLong();
    			}
    to
    Code:
    //Enter long
    			if (CrossAbove(...)
    				&& tradeok == 1)
    			{
    				EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
    			}

    #2
    sburtt, from a quick visual would not see anything standing out - would this be shown if you backtest the script now as well? The Enter() method would reverse automatically for you if needed, so if you were in a situation where the account would not have any position and then script would be set to execute live immediately, it would fire a 100000 order to reverse from a historical position - this would happen if you weren't synching account vs strateagy position up properly in immediately submit mode.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by sburtt View Post
      Hi I am running a live strategy with position size of 50,000. However this am I noticed the strategy was long 100,000 despite EntryHandling =EntryHandling.UniqueEntries;

      this is the body of my strategy, does somebody know what I am doing wrong? why did It take a position twice?
      Code:
       
              #region Variables
          private int tradeok = 1;
          private double RngFrac = 0.35;
              #endregion
       
              protected override void Initialize()
              {    
              CalculateOnBarClose = true;
          EntryHandling     =    EntryHandling.UniqueEntries;
          ExitOnClose = false;
          }
       
        protected override void OnBarUpdate()
              {
                  //Enter long
                  if (CrossAbove(...)
                      && tradeok == 1)
                  {
                      EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
                  }
       
                  //Enter short
                  if (CrossBelow(...)
                      && tradeok == 1)
                  {
                      EnterShortLimit(Close[0] + RngFrac * (High[0] - Low[0]));
                  }
       
                  // Exit short
                  if (Position.MarketPosition == MarketPosition.Short
                      && CrossAbove(...)
                      && tradeok == 1)
                  {
                      ExitShort();
                  }
       
                  //Exit long
                  if (Position.MarketPosition == MarketPosition.Long
                      && CrossBelow(...)
                      && tradeok == 1)
                  {
                      ExitLong();
                  }
       
                  if (Position.MarketPosition == MarketPosition.Long
                      && Time[0].DayOfWeek == DayOfWeek.Friday
                      && ToTime(Time[0]) > ToTime(17, 59, 0))
                  {
                      ExitLong();
                  }
       
       
                  if (Position.MarketPosition == MarketPosition.Short
                      && Time[0].DayOfWeek == DayOfWeek.Friday
                      && ToTime(Time[0]) > ToTime(17, 59, 0))
                  {
                      ExitShort();
                  }
       
                  if (Time[0].DayOfWeek == DayOfWeek.Sunday)
                  {
                      tradeok = 0;
                  }
       
                  if (Time[0].DayOfWeek == DayOfWeek.Monday
                      && ToTime(Time[0]) < ToTime(6, 0, 0))
                  {
                      tradeok = 0;
                  }
       
                  if (Time[0].DayOfWeek == DayOfWeek.Friday
                      && ToTime(Time[0]) >= ToTime(15, 59, 0))
                  {
                      tradeok = 0;
                  }    
       
                  else
                  {
                  tradeok = 1;
                  }
       
              }
      NOTICE I've been running this strategy for months without any problem, over the week-end I have changed my entry long (and short) rule from:

      Code:
      //Enter long
                  if (CrossAbove(...)
                      && tradeok == 1)
                  {
                      EnterLong();
                  }
      to
      Code:
      //Enter long
                  if (CrossAbove(...)
                      && tradeok == 1)
                  {
                      EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
                  }
      Your code, as written, will do a stop and reverse.

      I would surmise that your Strategy thought that you were in a position when your account was actually flat. The strategy got a signal and reversed you, so in your account, you will now be in a double position, as your account started from a flat position, not an inmarket position.

      Look in your log. You should see an exit order followed by an entry order. Those 2 orders will be in the same direction, so from flat, they will take you inmarket to a double position.

      Comment


        #4
        Originally posted by koganam View Post
        Your code, as written, will do a stop and reverse.

        I would surmise that your Strategy thought that you were in a position when your account was actually flat. The strategy got a signal and reversed you, so in your account, you will now be in a double position, as your account started from a flat position, not an inmarket position.

        Look in your log. You should see an exit order followed by an entry order. Those 2 orders will be in the same direction, so from flat, they will take you inmarket to a double position.
        koganam, this is exactly what happens. Lets say i am short, the exit short order will bring me back to flat, however the enter long limit order will then get me long ( assuming i was short, hence doubling up my position) this happens only in real trading, not in backtesting.

        From your experience do you think there is a way to avoid this happening?

        Please notice the strategy is coded in the way that the limit order to go long ( or short) is always left when the maket position is flat, HOWEVER my position will be flattened exactly at the same bar the limit order is entered, hence i don't think a market position check would work. Owuld maybe using MTF help me solve this issue?

        Thanks for your time

        Comment


          #5
          Originally posted by sburtt View Post
          koganam, this is exactly what happens. Lets say i am short, the exit short order will bring me back to flat, however the enter long limit order will then get me long ( assuming i was short, hence doubling up my position) this happens only in real trading, not in backtesting.

          From your experience do you think there is a way to avoid this happening?

          Please notice the strategy is coded in the way that the limit order to go long ( or short) is always left when the maket position is flat, HOWEVER my position will be flattened exactly at the same bar the limit order is entered, hence i don't think a market position check would work. Owuld maybe using MTF help me solve this issue?

          Thanks for your time
          For me, this usually happens if I have to start my Strategy late, after a signal would have been generated, if my strategy were running at the correct time.

          To handle it, I have a bool parameter that I can use to force the Strategy to run in RealTime only, so that all position data on historical bars gets ignored. Naturally, if you are then in a position and have to restart, historical position calculation would now be correct and match the existing position, so the parameter will have to be turned off, in that event.

          Pretty cumbersome, but the only thing that I could come up with that allows me to remain in control: I do not want NT placing orders in an attemp to synchronize my position, as that is too prone to being wrong; and I certainly do not want to wait until flat, when my account is already flat!

          Comment


            #6
            Originally posted by koganam View Post
            For me, this usually happens if I have to start my Strategy late, after a signal would have been generated, if my strategy were running at the correct time.

            To handle it, I have a bool parameter that I can use to force the Strategy to run in RealTime only, so that all position data on historical bars gets ignored. Naturally, if you are then in a position and have to restart, historical position calculation would now be correct and match the existing position, so the parameter will have to be turned off, in that event.

            Pretty cumbersome, but the only thing that I could come up with that allows me to remain in control: I do not want NT placing orders in an attemp to synchronize my position, as that is too prone to being wrong; and I certainly do not want to wait until flat, when my account is already flat!
            Thanks for replaying. I think i know what you mean, but I am quite sure that is not the problem. Let me try to explain further. I noticed this problem happening at every entry when running the script.

            Lets assume my strategy runs on 60 minutes chart and is currently short. Assume that the strategy is a SMA cross over that enters long via limit order only if a cross over occurs and the price retraces a fraction of the previous candle range (EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0])). The problem I have is that every time the fast SMA crosses above the slow SMA, immediately at the next 60 min bar the strategy exits the short position via market order, and simultaneously it leaves the EnterLongLimit. What I noticed is that the strategy actually leaves 2 EnterLongLimit (one to flatten the position, one to go long) not recognizing that I am already flat.

            Please inform me if what i am telling you is not clear enough, It's clear in my head, but i might not being expressing myself correctly.

            Thanks again for you time and helping find a turnaround at this problem

            Comment


              #7
              Originally posted by sburtt View Post
              Thanks for replaying. I think i know what you mean, but I am quite sure that is not the problem. Let me try to explain further. I noticed this problem happening at every entry when running the script.

              Lets assume my strategy runs on 60 minutes chart and is currently short. Assume that the strategy is a SMA cross over that enters long via limit order only if a cross over occurs and the price retraces a fraction of the previous candle range (EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0])). The problem I have is that every time the fast SMA crosses above the slow SMA, immediately at the next 60 min bar the strategy exits the short position via market order, and simultaneously it leaves the EnterLongLimit. What I noticed is that the strategy actually leaves 2 EnterLongLimit (one to flatten the position, one to go long) not recognizing that I am already flat.

              Please inform me if what i am telling you is not clear enough, It's clear in my head, but i might not being expressing myself correctly.

              Thanks again for you time and helping find a turnaround at this problem
              Maybe I am not understanding properly, but my experience with Stop-and-Reverse is that when the strategy gets the signal, it exits, then opens a trade in the opposite direction. (See picture).

              The only time that I have the strategy out of sync with the account, is usually because I either did not have the strategy running when a position would have been taken historically, or else NT failed to record the exit (or actually, on one occasion, did not exit) at end-of-day. In that case, I switch the strategy to realtime only, so that I can get the next trade; or if the market is at the same price or better than the historical trade entry price, I will manually enter the trade to sync the position, and leave the strategy to take it from there.
              Attached Files
              Last edited by koganam; 05-22-2013, 03:29 PM. Reason: Corrected spelling.

              Comment


                #8
                Originally posted by koganam View Post
                For me, this usually happens if I have to start my Strategy late, after a signal would have been generated, if my strategy were running at the correct time.

                To handle it, I have a bool parameter that I can use to force the Strategy to run in RealTime only, so that all position data on historical bars gets ignored. Naturally, if you are then in a position and have to restart, historical position calculation would now be correct and match the existing position, so the parameter will have to be turned off, in that event.

                Pretty cumbersome, but the only thing that I could come up with that allows me to remain in control: I do not want NT placing orders in an attemp to synchronize my position, as that is too prone to being wrong; and I certainly do not want to wait until flat, when my account is already flat!
                koganam, let me try to be more clear, I might have not explained myself properly.
                The strategy is NOT out of sync.
                The issue I have is due to how the script is coded. Have a look at this code (in particular condition 1 and 3 highlighted):
                Code:
                        protected override void Initialize()
                        {    
                        CalculateOnBarClose = true;
                    [B]EntryHandling     =    EntryHandling.UniqueEntries;[/B]
                    ExitOnClose = false;
                    }
                
                  protected override void OnBarUpdate()
                     [B]   {
                            //CONDITION 1 - Enter long
                            if (CrossAbove(SMA(fast),SMA(slow),1))
                            {
                                EnterLongLimit(Close[0] - 0.35* (High[0] - Low[0]));
                            }[/B]
                 
                            //CONDITION 2 - Enter short
                            if (CrossBelow(SMA(fast),SMA(slow),1))
                            {
                                EnterShortLimit(Close[0] + 0.35* (High[0] - Low[0]));
                            }
                 
                [B]            //CONDITION 3 - Exit short
                            if (Position.MarketPosition == MarketPosition.Short
                                && CrossAbove(SMA(fast),SMA(slow),1))
                            {
                                ExitShort();
                            }[/B]
                 
                            //CONDITION 4- Exit long
                            if (Position.MarketPosition == MarketPosition.Long
                                && CrossBelow(SMA(fast),SMA(slow),1))
                            {
                                ExitLong();
                            }
                e.i. let's assume that the strategy is live and I am in position, and my position is short 1 unit. Let's say that the CrossAbove condition occurs, OnBarUpdate both conditions1 and 3 will be true, hence both are executed. Immediately condition3 will go long 1 unit (at market) to exit the short position, whilst condition1 will leave 2 limit orders to Stop-and-Reverse my position to long 1 unit. However given condition3 has flatten my position already, condition1 will send me long 2 units (if executed). Basically condition1 doesn't recognize that condition3 has got me out of the short position.

                My question is this:

                Is there a way to disable the Stop-and-Reverse feature? This would solve my problem. Or any other solution, maybe using ELSE IF rather than IF to avoid this problem i am having?

                Comment


                  #9
                  Originally posted by sburtt View Post
                  koganam, let me try to be more clear, I might have not explained myself properly.
                  The strategy is NOT out of sync.
                  The issue I have is due to how the script is coded. Have a look at this code (in particular condition 1 and 3 highlighted):
                  Code:
                          protected override void Initialize()
                          {    
                          CalculateOnBarClose = true;
                      [B]EntryHandling     =    EntryHandling.UniqueEntries;[/B]
                      ExitOnClose = false;
                      }
                   
                    protected override void OnBarUpdate()
                       [B]  {[/B]
                  [B]           //CONDITION 1 - Enter long[/B]
                  [B]           if (CrossAbove(SMA(fast),SMA(slow),1))[/B]
                  [B]           {[/B]
                  [B]               EnterLongLimit(Close[0] - 0.35* (High[0] - Low[0]));[/B]
                  [B]           }[/B]
                   
                              //CONDITION 2 - Enter short
                              if (CrossBelow(SMA(fast),SMA(slow),1))
                              {
                                  EnterShortLimit(Close[0] + 0.35* (High[0] - Low[0]));
                              }
                   
                  [B]           //CONDITION 3 - Exit short[/B]
                  [B]           if (Position.MarketPosition == MarketPosition.Short[/B]
                  [B]               && CrossAbove(SMA(fast),SMA(slow),1))[/B]
                  [B]           {[/B]
                  [B]               ExitShort();[/B]
                  [B]           }[/B]
                   
                              //CONDITION 4- Exit long
                              if (Position.MarketPosition == MarketPosition.Long
                                  && CrossBelow(SMA(fast),SMA(slow),1))
                              {
                                  ExitLong();
                              }
                  e.i. let's assume that the strategy is live and I am in position, and my position is short 1 unit. Let's say that the CrossAbove condition occurs, OnBarUpdate both conditions1 and 3 will be true, hence both are executed. Immediately condition3 will go long 1 unit (at market) to exit the short position, whilst condition1 will leave 2 limit orders to Stop-and-Reverse my position to long 1 unit. However given condition3 has flatten my position already, condition1 will send me long 2 units (if executed). Basically condition1 doesn't recognize that condition3 has got me out of the short position.

                  My question is this:

                  Is there a way to disable the Stop-and-Reverse feature? This would solve my problem. Or any other solution, maybe using ELSE IF rather than IF to avoid this problem i am having?
                  On the face of it, what you describe seems to be incorrect, given the code that you have posted. Maybe you want to post a chart showing what you are describing.

                  Now I am confused though. The code you have posted looks very obviously to me like you want toStop&Reverse. If so, why not take advantage of an inbuilt feature, rather than seek ways to disable the feature in the first place?

                  However, this is the kind of situation that often arises when one does not write a technical spec. before coding. Often writing a spec looks like overkill, until what at first looked simple, simply seems to not work. If you will first completely describe, in verbose language or pseudocode, that which you want to code, it might be much faster to reach your goal.

                  Comment


                    #10
                    Originally posted by koganam View Post
                    On the face of it, what you describe seems to be incorrect, given the code that you have posted. Maybe you want to post a chart showing what you are describing.

                    Now I am confused though. The code you have posted looks very obviously to me like you want toStop&Reverse. If so, why not take advantage of an inbuilt feature, rather than seek ways to disable the feature in the first place?

                    However, this is the kind of situation that often arises when one does not write a technical spec. before coding. Often writing a spec looks like overkill, until what at first looked simple, simply seems to not work. If you will first completely describe, in verbose language or pseudocode, that which you want to code, it might be much faster to reach your goal.
                    Ok, lets make a step back.
                    The strategy I am using is very simple, below is what I am trying to achieve. You will notice that my entries are via limit orders and my exits are via market orders. Hence despite entering long and exiting short on the same condition (MA cross over) I don't want the strategy to stop-and-reverse. I have no guarantee that the limit order will be filled.

                    ENTER LONG
                    if (CrossAbove(SMA(fast),SMA(slow),1))
                    enter long via limit order (Close[0] - 0.35* (High[0] - Low[0]))

                    EXIT LONG
                    if (CrossBelow(SMA(fast),SMA(slow),1))
                    exit long via market order

                    ENTER SHORT
                    if (CrossBelow(SMA(fast),SMA(slow),1))
                    enter short via limit order (Close[0] + 0.35* (High[0] - Low[0]))

                    EXIT SHORT
                    if (CrossAbove(SMA(fast),SMA(slow),1))
                    exit short via market order

                    I want to be able to enter trades via limit orders and exit via market orders on the same condition (MA cross over) and always in the same bar update

                    Please let me know if this is clear now.

                    Comment


                      #11
                      Originally posted by sburtt View Post
                      Ok, lets make a step back.
                      The strategy I am using is very simple, below is what I am trying to achieve. You will notice that my entries are via limit orders and my exits are via market orders. Hence despite entering long and exiting short on the same condition (MA cross over) I don't want the strategy to stop-and-reverse. I have no guarantee that the limit order will be filled.

                      ENTER LONG
                      if (CrossAbove(SMA(fast),SMA(slow),1))
                      enter long via limit order (Close[0] - 0.35* (High[0] - Low[0]))

                      EXIT LONG
                      if (CrossBelow(SMA(fast),SMA(slow),1))
                      exit long via market order

                      ENTER SHORT
                      if (CrossBelow(SMA(fast),SMA(slow),1))
                      enter short via limit order (Close[0] + 0.35* (High[0] - Low[0]))

                      EXIT SHORT
                      if (CrossAbove(SMA(fast),SMA(slow),1))
                      exit short via market order

                      I want to be able to enter trades via limit orders and exit via market orders on the same condition (MA cross over) and always in the same bar update

                      Please let me know if this is clear now.
                      It is clear, and you cannot do this part with CalculateOnBarClose = true: "I want to be able to enter trades via limit orders and exit via market orders on the same condition (MA cross over) and always in the same bar update"

                      Here is a very long thread, where I am the protagonist, where we discussed this: http://www.ninjatrader.com/support/f...+limit+reverse

                      You will see that my initial post essentially duplicates the method that you are asking about, and the same question. Heck, even the title of my thread is that same question!
                      Last edited by koganam; 05-05-2013, 05:42 PM. Reason: Corrected statement.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        It is clear, and you cannot do this part with CalculateOnBarClose = false: "I want to be able to enter trades via limit orders and exit via market orders on the same condition (MA cross over) and always in the same bar update"

                        Here is a very long thread, where I am the protagonist, where we discussed this: http://www.ninjatrader.com/support/f...+limit+reverse

                        You will see that my initial post essentially duplicates the method that you are asking about, and the same question. Heck, even the title of my thread is that same question!
                        Thanks, sounds promising. Tomorrow morning (now it's 00.17am in London) I will read the post, hopefully you found a way around this issue. Again thanks

                        Comment


                          #13
                          Originally posted by sburtt View Post
                          Thanks, sounds promising. Tomorrow morning (now it's 00.17am in London) I will read the post, hopefully you found a way around this issue. Again thanks
                          Oops. I meant that you cannot do it with CalculateOnBarClose = true. I have edited the original response to correct this.

                          One way to finagle it is to use CalculateOnBarClose = false, with a boolean flag. If you do however, you will find that it does not backtest quite correctly.

                          Comment


                            #14
                            Originally posted by koganam View Post
                            Oops. I meant that you cannot do it with CalculateOnBarClose = true. I have edited the original response to correct this.

                            One way to finagle it is to use CalculateOnBarClose = false, with a boolean flag. If you do however, you will find that it does not backtest quite correctly.
                            Koganam, reading your threads bring me to 3 questions:

                            1. basically you mean that setting CalculateOnBarClose = false and using the script reported below, I should be able to handle this issue? please answer yes or no

                            Code:
                            private bool _boolReverseOnOppositeSignal	= [B]false[/B];
                            
                             CalculateOnBarClose = true.
                            	private void GoShort(string strEntryName)
                            		{
                            		        if (this._boolReverseOnOppositeSignal) ExitLong();
                            			EnterShortLimit(DefaultQuantity, Close[0], strEntryName);
                                              }
                            2. don't you think that the use of CalculateOnBarClose = false is risky, as it could generate more trades than in the case CalculateOnBarClose = true?

                            3. what exactly do I need boolean flag for? wouldn't i get the same by using the code without, like below:
                            Code:
                             CalculateOnBarClose = [B]false[/B];
                            	private void GoShort(string strEntryName)
                            		{
                            		        ExitLong();
                            			EnterShortLimit(DefaultQuantity, Close[0], strEntryName);
                                              }
                            Last edited by sburtt; 05-06-2013, 02:13 AM.

                            Comment


                              #15
                              possible solution

                              Koganam
                              i might have find a way to avoid this problem whist keeping CalculateOnBarClose = true;
                              please correct me if wrong.

                              Running your script what happens is that the limit order is never issued or executed, script below

                              Code:
                              CalculateOnBarClose = true;
                              private void GoShort(string strEntryName)
                                     {
                              	ExitLong();
                              	EnterShortLimit(DefaultQuantity, Close[0], strEntryName);
                                      }
                              running my script, I have a similar, but different issue. I end up doubling my position if executed, because my limit order would work as stop-and-reverse, but this ignores the fact that I would be already flat due to the market order beeing executed too, script below
                              Code:
                              CalculateOnBarClose = true;
                              
                                protected override void OnBarUpdate()
                              //Enter short
                                          if (CrossBelow())
                                          {
                                              EnterShortLimit(Close[0] + 0.35* (High[0] - Low[0]));
                                          }
                               
                              //Exit long
                                          if (Position.MarketPosition == MarketPosition.Long
                                              && CrossBelow())
                                          {
                                              ExitLong();
                                          }
                              * curious enough if I invert the sequence of the script (//Exit long on top and //Enter long below) my limit order is never issued or executed, as it happens in your script.

                              what i think could be a quite good solution is using multi time frame. I am running this strategy on a 240min chart. If I exit my position at market on the primary bar series (240min) and have the limit order running on the secondary bar series (1min) for the entire 240 min bar, I will reduce the risk of doubling up my position to only 1 min (the first minute) rather than 240min, this could be a good trade-off. Below is the script I intend to test:
                              Code:
                               Add(PeriodType.Minute,1);
                              CalculateOnBarClose = true;
                              
                                protected override void OnBarUpdate()
                              if(BarsInProgress == 0)
                              {
                              //Enter short
                                          if (CrossBelow())
                                          {
                                              EnterShortLimit([B]1[/B],Close[0] + 0.35* (High[0] - Low[0]));
                                          }
                               
                              //Exit long
                                          if (Position.MarketPosition == MarketPosition.Long
                                              && CrossBelow())
                                          {
                                              ExitLong();
                                          }
                              }
                              I've back tested this and results are exactly the same as in my original strategy. In back testing it looks like this could be the way to go. Please let me know if you understand what I am trying to say here. Could you tell me if you think this makes sense and could work?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ageeholdings, Today, 07:43 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ageeholdings  
                              Started by pibrew, Today, 06:37 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post pibrew
                              by pibrew
                               
                              Started by rbeckmann05, Yesterday, 06:48 PM
                              1 response
                              14 views
                              0 likes
                              Last Post bltdavid  
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post burtoninlondon  
                              Working...
                              X