Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting Stop Loss between VWAP and LOD

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

    Setting Stop Loss between VWAP and LOD

    I am trying to make a long order and set the stop at 1/3 the way between VWAP and LOD.
    It compiles fine , but I get Error on calling 'OnStateChange' method Object: reference not set to an instance of an object.
    Here is the code that I think is the issue

    EMA1 = EMA(Close, 9);
    VWAP1 = VWAP(Close);
    VWAP2 = VWAP(Close);
    CurrentDayOHL1 = CurrentDayOHL(Close);
    Stopticks =(int)((VWAP2.PlotVWAP[0] - CurrentDayOHL1.CurrentLow[0])/3);
    BarCounter1 = BarCounter(Close, true, Brushes.Gray, 14, 50, true);
    SetStopLoss(@"Long",CalculationMode.Ticks, Stopticks, false);
    SetProfitTarget(@"Long", CalculationMode.Ticks, Stopticks);

    #2
    Hello BrJessey,

    Thanks for your post.

    "Error on calling 'OnStateChange' method Object: reference not set to an instance of an object."

    This error indicates that something you are accessing in the script is not defined at the time you are accessing it.

    In the code you shared, this is not the correct VWAP syntax for defining a VWAP indicator. The VWAP syntax is noted in the help guide and can be seen below.

    OrderFlowVWAP(VWAPResolution resolution, TradingHours tradingHoursInstance, VWAPStandardDeviations numStandardDeviations, double sD1Multiplier, double sD2Multiplier, double sD3Multiplier)

    See this help guide page for more information on accessing Order Flow VWAP values and sample code: https://ninjatrader.com/support/help...flow_vwap2.htm

    Further, indicator values should be accessed in OnBarUpdate(). You could consider setting up your Stopticks calculation in OnBarUpdate() and then use Exit methods in OnBarUpdate() for your stop loss and profit target orders.

    Attached is a simple example script demonstrating using Exit methods for stop loss and profit target orders which you might find helpful.

    Managed Approach: https://ninjatrader.com/support/help...d_approach.htm
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X