• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SamplePriceModification

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

    SamplePriceModification

    Hello, how do I add short position in the strategy attached, thank you.
    Mark.
    Attached Files

    #2
    Hello snakepatob,

    Thank you for your post.

    In general, a short position can be added with the reverse conditions as the long. In this strategy there would need to be a few changes. Below is and example of using the reverse of what is used for the long and considering the position before taking a new position.
    Code:
    			// Resets the stop loss to the original value when all positions are closed
    			if (Position.MarketPosition == MarketPosition.Flat)
    			{
    				SetStopLoss(CalculationMode.Ticks, stoplossticks);
    
    				// Entry Condition: Increasing price along with RSI oversold condition
    				if (Close[0] > Close[1] && RSI(14, 3)[0] <= 30)
    				{
    					EnterLong();
    				}
    				
    				// Opposite of long condition
    				if (Close[0] < Close[1] && RSI(14, 3)[0] >= 30)
    				{
    					EnterShort();
    				}
    			
    			}
    			
    			
    
    			// If a short or long position is open, allow for stop loss modification to breakeven
    			else if (Position.MarketPosition == MarketPosition.Long)
    			{
    				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
    				if (Close[0] > Position.AvgPrice + 50 * TickSize)
    				{
    					SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    				}
    			}
    			else if (Position.MarketPosition == MarketPosition.Short)
    			{
    				// Once the price is greater than entry price-50 ticks, set stop loss to breakeven
    				if (Close[0] < Position.AvgPrice - 50 * TickSize)
    				{
    					SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    				}
    			}
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Patrik,
      thanks for listening, I could include the code and compile.
      Without your help I would not have succeeded.
      Mark.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rontronimous, Yesterday, 05:55 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by brunoviveiros, Today, 04:26 AM
      0 responses
      1 view
      0 likes
      Last Post brunoviveiros  
      Started by Erhard, Today, 04:24 AM
      0 responses
      5 views
      0 likes
      Last Post Erhard
      by Erhard
       
      Started by StevenNelson, 11-19-2019, 05:39 AM
      3 responses
      16 views
      0 likes
      Last Post brucerobinson  
      Started by guidoisot, Today, 03:01 AM
      0 responses
      8 views
      0 likes
      Last Post guidoisot  
      Working...
      X