Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lowest prize of lowestBar between 2 signals

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

    Lowest prize of lowestBar between 2 signals


    Hello, I am looking for how to calculate the lowest price and the candle between 2 signals. Attached code example.
    The value I am looking for is the Low of the lowest candle from the CrossBelow ema20 / sma200 (paints the background in red) to the CrossAbove (paints the bottom in green)

    i have tried:
    MIN1 = MIN(Low, ultima-primera); but i get error negative value

    Thank you!



    PHP Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class 
    aaapreciohi Strategy
    {
    private 
    int primera;
    private 
    int ultima;
    private 
    double preciominimo;
    private 
    int estado;


    private 
    EMA EMA1;
    private 
    EMA EMA2;
    private 
    MIN MIN1;


    protected 
    override void OnStateChange()
    {
    if (
    State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name "aaapreciohi";
    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;
    primera 0;
    ultima 0;
    preciominimo 0;
    estado 0;
    }
    else if (
    State == State.Configure)
    {
    }
    else if (
    State == State.DataLoaded)
    {
    EMA1 EMA(Close14);
    EMA2 EMA(Close200);
    EMA1.Plots[0].Brush Brushes.Black;
    EMA2.Plots[0].Brush Brushes.Red;
    MIN1 MIN(Low50); // si el cross below no existe antes de que ocurra el crossabove, el min es negativo, da error y no se puede activar.
    AddChartIndicator(EMA1);
    AddChartIndicator(EMA2);
    AddChartIndicator(MIN1);
    }
    }

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

    if (
    CurrentBars[0] < 200)
    return;


    // Set 1
    if (CrossBelow(EMA1EMA21))
    {
    primera CurrentBars[0];
    BackBrush Brushes.Crimson;
    Print (
    "primera "+primera+" " Convert.ToString(Times[0][0].TimeOfDay));
    }

    // Set 2
    if (CrossAbove(EMA1EMA21))
    {
    ultima=CurrentBars[0];
    primera 0;
    Print (
    "ultima "+ultima+" " Convert.ToString(Times[0][0].TimeOfDay));
    BackBrush Brushes.Green;
    preciominimo MIN1[0];
    Draw.Dot(this, @"velaCruceRed"false0preciominimoBrushes.Red);
    }
    }
    }


    #2
    Hi manueldecastro,
    I'm not sure, if I quite understand the code. Any specific reason why you (seem to) reset "primera" as soon as you have the opposite cross and set "ultima"?
    I think, both of them need to carry the barnumber of their (respective latest) occurrence. The resulting difference then indicates the lookback period from latest occurence to prior (opposite) occurrence.
    NT-Roland

    Comment


      #3
      Hi Roland.


      Resetting "primera" may not make sense. What I am looking for is the low of the lowest candle between "primera" and "ultima".

      Surely there will be some simple way. I have tried the low of the lowestbar, and other options but I can't.

      Comment


        #4
        Hello manueldecastro,

        Thank you for the post.

        If you are trying to find the MIN or MAX of an arbitrary range of bars you could use a for loop for that purpose. You are already storing the bar indexes for the condition, once you have both indexes populated you could run a loop like the following. I made a quick example that uses the CurrentBar as a starting index and loops backwards to the second index which is just 10 bars in the example.

        Also as NT-Roland mentioned, resetting the primera is likely not needed, you would only want to reset that after you do the loop or find the min value you needed. That likely needs removed from the second condition and placed after the print in the below sample.

        Code:
        if(CurrentBar < 10) return;
        int index1 = CurrentBar;
        int index2 = CurrentBar - 10;
        double min = 999999;
        for(int i = index1; i > index2; i--)
        {
           if(Close.GetValueAt(i) < min)
           {
              min = Close.GetValueAt(i);
           }
        }
        Print(min);

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

        Comment


          #5
          wha i need is min value between "primera" y "ultima" but i dont get this value with this sample code


          HTML Code:
          protected override void OnBarUpdate()
          {
          // if (BarsInProgress != 0)
          // return;
          
          // if (CurrentBars[0] < 10)
          // return;
          if(CurrentBar < 40) return;
          int index1 = primera;
          int index2 = ultima;
          double min = 999999;
          for(int i = index1; i > index2; i--)
          {
          if(Low.GetValueAt(i) < min)
          {
          min = Low.GetValueAt(i);
          Draw.ArrowUp(this, @"arco alcanzado" + CurrentBar, false, 0, min, Brushes.Blue);
          }
          }
          Print(min);
          
          // Set 1
          if (CrossBelow(EMA1, EMA2, 1))
          {
          primera=CurrentBar;
          }
          
          
          
          // Set 2
          if (CrossAbove(EMA1, EMA2, 1))
          {
          ultima=CurrentBar;
          }
          
          }
          Last edited by manueldecastro; 04-28-2021, 04:42 AM.

          Comment


            #6
            Hello manueldecastro,

            Your sets are both using the same condition so the indexes you are setting are the same. Did you intend to use something different for the second condition in set2?

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

            Comment


              #7
              i got it with lowest bar and highestbar.
              now, i have similar problem with indicators. i cant code similar because i get highestbar but i need highest value of momentum

              MAX1 = MAX(Momentum(14), "xoUp");
              supose that y need highest value of momentum (14) between currentbar and EMA1 crossabove EMA".
              if CrossAbove ema1 ema2... (pseudocode)
              {xoUP=CurrentBar}

              i have tested :
              MAX1 = MAX(Momentum(14), "CurrentBar-xoUp"); but i got a negative value. I dont understand.
              Need help! please

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bowling, Today, 06:16 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by systemtrader4, Today, 01:54 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by Futurestrader00, Today, 01:54 AM
              1 response
              25 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by timmbbo, Today, 01:40 AM
              2 responses
              10 views
              0 likes
              Last Post NT-Roland  
              Started by BGWTEX, Yesterday, 07:20 PM
              0 responses
              7 views
              0 likes
              Last Post BGWTEX
              by BGWTEX
               
              Working...
              X