Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using VWAP as a crossover in NT Editor strategy?

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

    Using VWAP as a crossover in NT Editor strategy?

    Hello,

    I am trying to use VWAP as a crossover criteria for entering my strategy using NinjaScript Editor. I have OrderFlow+ and added this code to my script:

    Code:
    double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
    Print("The current VWAP with a standard resolution on CME US Index Futures RTH is " + VWAPValue.ToString());
    ​
    And for the sake of the question, lets say this is what I would like my entry to be:

    Code:
    if (market_open && (DailyProfit >= -1200))
                //if (market_open)
                {
                    if (Close[0] >= VWAPValue[0])
                    {
                    EnterLong(Convert.ToInt32(DefaultQuantity), "");​
    And this is not functioning. First, it says it cannot convert a double to int. But even if I resolve this, there are other issues with the script not compiling properly.

    How can I just simply program it to enter whenever price reaches and crosses over VWAP?

    Thank you,

    Steve

    #2
    Hello eleximp224,

    Did you make your script exactly like the help guide sample which adds the secondary data series and calls the vwap from BarsInProgress 1?

    The error annot convert a double to an int means that somewhere you are trying to use a double where an int is required. Which specific line is having an error?

    Comment


      #3
      I made it exactly like that help guide sample where BarsInProgress=1. I think the bigger issue besides the double vs. int is it is saying "The name 'VWAPValue' does not exist in the current context" On multiple lines (120,121,124, 133, 137, and some more)
      1. I have VWAPValue being calculated if BarsInProgress == 0, and I checked the output window and this is functioning when I remove all references to VWAPValue in my code. It is outputting the VWAP.
      2. Next, it moves to BarsInProgress==1 for the OrderFlowVWAP secondary tick series cached indicator sync. This works fine
      3. The issue arises next when I try to use my entry logic to enter a trade.
        • I am sure I am somehow in the wrong context. Is this because the BarsInProgress is different? Should I be placing my entry/exit logic somewhere else?
      I've attached my simplified test code below. If I can get this working, I will be able to add the more complex if statements I am hoping to add later. Thank you
      Attached Files

      Comment


        #4
        Hello eleximp224,

        The custom code you add needs to go inside the condition:

        Code:
        if (BarsInProgress == 0)
        {
        
        }
        That is where you defined the variable so the code that uses that variable needs to be inside that condition and below where you defined the variable. The BarsInProgress 1 condition is just to call the vwap to update it on the tick level, all of your code will go in the BIP 0 condition.


        Code:
        if (BarsInProgress == 0)
        {​
        double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
        ​
        ......
        
        Values[1][0] = VWAPValue[0];​
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        116 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        61 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        40 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        44 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        82 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X