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

Using Pivot Value for StopLoss and Profit

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

    Using Pivot Value for StopLoss and Profit

    I initially used the strategy builder to enter a trade when price closes above an indicator value. I am having some issues setting the profit and stop based on values from that same indicator. I am wanting to use the value from camarilla pivot R3 for profit and camarilla S4 for stop loss. I have unlocked the code to try and make the SetProfitTarget() to be CamarillaPivot.R3, but im getting an error. I have copied the code here. I am sure its something silly. Please help!

    `

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class ESLongS3 : Strategy
    {
    private CamarillaPivots CamarillaPivots1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ESLongS3";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    CamarillaPivots1 = CamarillaPivots(Close, PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20);
    SetProfitTarget(CalculationMode.Price, (CamarillaPivots1.R3));
    SetStopLoss(CalculationMode.Price, (CamarillaPivots1.S4));

    }
    }

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossAbove(Close, CamarillaPivots1.S3, 1))
    {
    EnterLong(1, @"LongS3");
    }

    }
    }
    }



    #2
    Hello charliefoxtrot,

    Welcome to the NinjaTrader forums!

    Unfortunately, in the Strategy Builder Set methods cannot be set to dynamic prices such as series or indicator plot values.
    Instead, use an exit order such as 'Exit long position with a limit order' within the actions 'Do the following' section of the Condition Builder.

    Below is a link to an example.
    Hello support team, I have 2 dataseries, a 1minute to detect the ATR value. Now I would like to set the stoploss and profit target based on the actual ATR Value Example: Stoploss 2xATR Profittarget 3xATR value 1. How can this be done with builder, I have no coding experience 2. Later I would like to have the possibility to


    Or alternatively, unlock the script and you can manually code setting set methods within OnBarUpdate().
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pibrew, Today, 06:37 AM
    0 responses
    0 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    12 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
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Working...
    X