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

stop loss

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

    stop loss

    hi

    i dont know if im crazy or just not able to think logic.

    my strategy is perfectly handling my long stops but not my short stops and i have no idea why. if someone could help me pls

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    }

    // If a 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+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + breakeventicks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 3);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + plusstop1ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 2);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + plusstop2ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 5);
    }

    }

    // If a short position is open, allow for stop loss modification to breakeven
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - breakeventicks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 3);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - plusstop1ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 2);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - plusstop2ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 5);
    }

    }

    #2
    Raggamuffin,

    Please be more specific as to what you want it to do and what it actual does. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      in the variables i have this:

      private int breakeventicks =7;
      private int plusstop1ticks =12;
      .
      .
      .

      lets say i run this strategy 3 times

      1 has a profit target of 20 ticks
      1 has a profit target of 30 ticks and the third target is 50 ticks

      and it does that:




      you see the stop loss in the first pic is perfect and in pic 2 the stop loss is negative but it should be like in pic 1 in positive terrain and i dont understand why.

      Comment


        #4
        You should add Print() along each step where you think you are amending your stops. Then you will know if an amend every was submitted. If no amend was submitted you then need to debug out your if-statements by printing those values so you can evaluate by hand.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ETFVoyageur, Today, 12:52 AM
        0 responses
        2 views
        0 likes
        Last Post ETFVoyageur  
        Started by Board game geek, Yesterday, 02:20 AM
        2 responses
        21 views
        0 likes
        Last Post Board game geek  
        Started by jackiegils, Yesterday, 11:05 PM
        0 responses
        5 views
        0 likes
        Last Post jackiegils  
        Started by cre8able, 05-09-2024, 09:15 PM
        2 responses
        17 views
        0 likes
        Last Post cre8able  
        Started by Trader146, Yesterday, 09:17 PM
        0 responses
        10 views
        0 likes
        Last Post Trader146  
        Working...
        X