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

Ninja Script - Target twice as the previous

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

    Ninja Script - Target twice as the previous

    Hi all,

    Basically, I want a 2:1 risk-reward strategy.
    The stop-loss should be placed in the low of the previous bar (this I already got it).
    Any help for the profit take logic would be appreciated.
    Kind regards,
    Jose


    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((CandlestickPattern1[0] != 0)
    && (GetCurrentAsk(0) > EMA1[0])
    && (RSI1.Avg[0] > 50))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity),"MyLong Entry" + CurrentBar);
    SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);
    SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false);
    }


    }

    #2
    Hello josedaniel,

    Thanks for the post.

    Could you conform for me, what are you trying to do twice as the previous?

    Are you asking for a target which has a price twice the previous high?

    I see you have a target using Percent, are you asking about getting 2%?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Yes, I realized the Tittle was misleading once I´ve posted it.
      I want the target to be twice as big as the Stop-loss.
      If SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false); let´s say is 20 ticks. Then Target should be 40 ticks.
      Basically, accomplishing a 2:1 Risk Reward

      PS: "SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);" was just to put something there in the meantime.
      Kind Regards,
      Jose

      Comment


        #4
        Hello josedaniel,

        Thanks for clearing that up.

        To do that you would need to know the difference between the bars in ticks and then you can just use the Ticks mode:

        Code:
        double ticks = (Close[0] - Low[1]) / TickSize;
        Assuming the logic you have is checking for some kind of up trend this should work, if the previous bars low was greater than the close it would end up being a negative number which would not work.

        To get twice the ticks for the target you would use ticks * 2


        One other side note is that the set methods need to be called before the entry to set them up:

        Code:
        SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);
        SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false);
        EnterLong(Convert.ToInt32(DefaultQuantity),"MyLong Entry" + CurrentBar);

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by f.saeidi, Today, 12:14 PM
        4 responses
        11 views
        0 likes
        Last Post f.saeidi  
        Started by Russ Moreland, Today, 12:54 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by philmg, Today, 12:55 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by TradeForge, 04-19-2024, 02:09 AM
        2 responses
        32 views
        0 likes
        Last Post TradeForge  
        Started by aprilfool, 12-03-2022, 03:01 PM
        3 responses
        329 views
        0 likes
        Last Post NinjaTrader_Adrian  
        Working...
        X