iam new in C# and after 5 Days triying to realise a simple Strategy with no sucess i search help
For my first Strategy i use only Draw.ArropUl/Down and no Entryshort/longs, to see what happens.
What i want is:
1. Draw Backgroundcolor of Chart Green if CCI > 50 until CCI < -50
2. Draw Backgroundcolor of Chart Red if CCI < -50 until CCI > 50
3. If Chart is Green then search for a vaildate Longretest (point 4) and if Chart Red then search for a validate Shortretest (Point 5)
4. When Close < Kama then Longrestest = true and when on an other Bar Close > Kama then Draw.ArrowUp (see Picture)
5. When Close > Kama then Shortretest = true and when on an other Bar Close < Kama then Draw ArrowDown (see Picture)
Thats all, but for me to hard to programm first time
What i have:
#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 ArFTest : Strategy { private int CCI_Wert; private bool LongRetest; private bool ShortRetest; private CCI CCI1; private KAMA KAMA1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "ArFTest"; Calculate = Calculate.OnPriceChange; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.Infinite; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = true; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 50; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; //CCI_Wert = 0; LongRetest = false; ShortRetest = false; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { CCI1 = CCI(Close, 21); KAMA1 = KAMA(Close, 2, 12, 30); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Hintergrund_Farbe soll je nach CCI Richtung eingestellt werden //Long if ((CCI1[0] > 50) || (CCI_Wert == 1) ) { CCI_Wert = 1; BackBrushAll = Brushes.Olive; } // Short if ((CCI1[0] < -50) || (CCI_Wert == -1) ) { CCI_Wert = -1; BackBrushAll = Brushes.Salmon; } // Set 3 if ((CCI_Wert == 1) && (CrossBelow(CCI1, KAMA1, 1)) ) { LongRetest = true; } // Set 4 if ((CCI_Wert == -1) && (Close[1] > KAMA1[1]) && (Close[2] < KAMA1[2])) { ShortRetest = true; } // Set 5 if ((LongRetest == true) && (Close[1] > KAMA1[1])) { Draw.ArrowUp(this, @"ArFTest Arrow up_1", true, 1, Low[1], Brushes.Black); LongRetest = false; ShortRetest = false; } // Set 6 if ((ShortRetest == true) && (Close[1] < KAMA1[1])) { Draw.ArrowDown(this, @"ArFTest Arrow down_1", false, 1, High[1], Brushes.Red); ShortRetest = false; LongRetest = false; } } } }
Many Thanks and have i nice Day.
Comment