• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Not Working As Coded

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

    Strategy Not Working As Coded

    This is the coded part. Basically trying to sell when above Oscillator is above 75 then crosses below 78 and buy when crossabove 26. I'm not worrying as much about buying at the moment as I'm just trying to get going short working properly.

    Within the attached photo you will see that the strategy should have entered short at the begging of the blue line and exited at the end. My question is:
    why in the world is this not working at coded? Is there a maximum number of if statements then it doesn't respond as well? It's as if it only reads 25% of my if-statements or something.

    #region Variables
    // Wizard generated variables
    private int my_TakeProfit = 19; // Default setting for My_TakeProfit
    // User defined variables (add any user defined variables below)
    private int bars_Ago = 0;
    private int ulte_Fast = 7;
    private int ulte_Int = 14;
    private int ulte_Slow = 28;
    private int oB_Num = 78;
    private int oS_Num = 26;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    DefaultQuantity = 10000;
    Add(UltimateOscillator(Ulte_Fast, Ulte_Int, Ulte_Slow));
    SetStopLoss("", CalculationMode.Ticks, 200, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Short Section
    #region Short


    // If UO goes above OB_Num then Crosses below the OB_Num it will then finally enter short.
    if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] >= 75
    && CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1))
    {
    EnterShort(DefaultQuantity, "Shorting D1");
    }
    // If our position is open short and the market then goes back above the OB_Num we exit the position taking our loss as soon as possible.
    else if ( Position.MarketPosition == MarketPosition.Short
    && CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
    {
    ExitShort("", "Exiting D1 S");
    }

    else if ( Position.MarketPosition == MarketPosition.Short
    && UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OB_Num +1))
    {
    ExitShort("", "Exit Short Profit");
    }

    else if ( Position.MarketPosition == MarketPosition.Short
    && UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= 50 )
    {
    if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), 40, 1) )
    {
    ExitShort("","Exit Short Profit");
    }
    }
    #endregion




    #region Long
    else if( Position.MarketPosition == MarketPosition.Long
    && CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
    {
    ExitLong("", "Exit Long Profit");
    }
    // OverSold Section
    // If UO is lessthan or equal to OS_Num we proceed.
    else if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OS_Num +1) )
    {
    // If we are under oversold number then crossabove it we will then enter long
    if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
    {
    EnterLong(DefaultQuantity, "Long D1");
    }
    }
    // If position is == long and the UO falls below the oversold number we exit long position to take our loss.
    else if ( Position.MarketPosition == MarketPosition.Long
    && CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
    {
    ExitLong("", "Exiting D1 L");
    }

    #endregion
    Attached Files

    #2
    Originally posted by andyshear View Post
    This is the coded part. Basically trying to sell when above Oscillator is above 75 then crosses below 78 and buy when crossabove 26. I'm not worrying as much about buying at the moment as I'm just trying to get going short working properly.

    Within the attached photo you will see that the strategy should have entered short at the begging of the blue line and exited at the end. My question is:
    why in the world is this not working at coded? Is there a maximum number of if statements then it doesn't respond as well? It's as if it only reads 25% of my if-statements or something.

    #region Variables
    // Wizard generated variables
    private int my_TakeProfit = 19; // Default setting for My_TakeProfit
    // User defined variables (add any user defined variables below)
    private int bars_Ago = 0;
    private int ulte_Fast = 7;
    private int ulte_Int = 14;
    private int ulte_Slow = 28;
    private int oB_Num = 78;
    private int oS_Num = 26;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    DefaultQuantity = 10000;
    Add(UltimateOscillator(Ulte_Fast, Ulte_Int, Ulte_Slow));
    SetStopLoss("", CalculationMode.Ticks, 200, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Short Section
    #region Short


    // If UO goes above OB_Num then Crosses below the OB_Num it will then finally enter short.
    if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] >= 75
    && CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1))
    {
    EnterShort(DefaultQuantity, "Shorting D1");
    }
    // If our position is open short and the market then goes back above the OB_Num we exit the position taking our loss as soon as possible.
    else if ( Position.MarketPosition == MarketPosition.Short
    && CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
    {
    ExitShort("", "Exiting D1 S");
    }

    else if ( Position.MarketPosition == MarketPosition.Short
    && UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OB_Num +1))
    {
    ExitShort("", "Exit Short Profit");
    }

    else if ( Position.MarketPosition == MarketPosition.Short
    && UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= 50 )
    {
    if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), 40, 1) )
    {
    ExitShort("","Exit Short Profit");
    }
    }
    #endregion




    #region Long
    else if( Position.MarketPosition == MarketPosition.Long
    && CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
    {
    ExitLong("", "Exit Long Profit");
    }
    // OverSold Section
    // If UO is lessthan or equal to OS_Num we proceed.
    else if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OS_Num +1) )
    {
    // If we are under oversold number then crossabove it we will then enter long
    if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
    {
    EnterLong(DefaultQuantity, "Long D1");
    }
    }
    // If position is == long and the UO falls below the oversold number we exit long position to take our loss.
    else if ( Position.MarketPosition == MarketPosition.Long
    && CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
    {
    ExitLong("", "Exiting D1 L");
    }

    #endregion
    Starting from this thread, and reading the links therein might tell you why. After all, you are using a Renko chart.

    ref: http://ninjatrader.com/support/forum...d.php?p=446249

    Comment


      #3
      Hello andyshear,

      I would recommend adding a print to your script that prints the values of the variables used in the if statement.

      Below is a link to a video that demonstrates.
      https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

      What was the value of the UltimateOscillator?
      Is this equal to or below 75 in the print?

      What was the value of the UltimateOscillator on the previous bar?
      What was the value of the OB_Num variable on the previous bar?
      What was the value of the UltimateOscillator on the current bar?
      What was the value of the OB_Num variable on the current bar? (With the included code this value would remain the same, but this is good to print for a clear comparison)


      As a tip, to export a NinjaTrader 7 NinjaScript do the following:
      1. Click File -> Utilities -> Export NinjaScript
      2. Enter a unique name for the file in the value for 'File name:'
      3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
      4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message

      By default your exported file will be in the following location:
      • (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript\<export_file_name.z ip>

      Below is a link to the help guide on Exporting NinjaScripts.
      http://www.ninjatrader.com/support/h...nt7/export.htm
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jayfutures23, Today, 09:32 AM
      0 responses
      1 view
      0 likes
      Last Post jayfutures23  
      Started by dshalom9, Today, 08:36 AM
      9 responses
      17 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by stock_wizard_49, 07-11-2020, 06:57 PM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Started by asmmbillah, Yesterday, 03:03 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by AspenHiker, Today, 08:37 AM
      0 responses
      7 views
      0 likes
      Last Post AspenHiker  
      Working...
      X