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!
#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(Close, 14);
EMA2 = EMA(Close, 200);
EMA1.Plots[0].Brush = Brushes.Black;
EMA2.Plots[0].Brush = Brushes.Red;
MIN1 = MIN(Low, 50); // 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(EMA1, EMA2, 1))
{
primera = CurrentBars[0];
BackBrush = Brushes.Crimson;
Print ("primera "+primera+" " + Convert.ToString(Times[0][0].TimeOfDay));
}
// Set 2
if (CrossAbove(EMA1, EMA2, 1))
{
ultima=CurrentBars[0];
primera = 0;
Print ("ultima "+ultima+" " + Convert.ToString(Times[0][0].TimeOfDay));
BackBrush = Brushes.Green;
preciominimo = MIN1[0];
Draw.Dot(this, @"velaCruceRed", false, 0, preciominimo, Brushes.Red);
}
}
}
}
Comment