I'm a newbie with ninjascript and with coding in general
I'm trying to put some ideas into code
I want the strategy to place the trade only for the first 2 retrace of price and stochastic
after there is a crossover in the 2 ema's
I know I'm doing something wrong
Any ideas on how i can approach this?
private EMA EMA1; private SMA SMA1; private Stochastics Stochastics2; private bool firstretrace = false; private bool secondretrace= false; protected override void OnStateChange() { if (State == State.SetDefaults) { FastEMA = 15; SlowSMA = 50; StokK = 5; StokD = 3; StokS = 2; } protected override void OnBarUpdate() { if (CurrentBars[0] < 2 || CurrentBars[1] < 1) return; if ((CrossBelow(Stochastics2.K, 20, 1)) && (Close[0] < EMA1[0]) &&(EMA1[0] > SMA1[0])) { firstretrace = true; } if ((firstretrace == false) && (Close[0] < EMA1[0]) && (CrossBelow(Stochastics2.K, 20, 1)) &&(EMA1[0] > SMA1[0])) { secondretrace = true; } // Long if ((CrossAbove(Stochastics2.K, Stochastics2.D, 1)) //&& (EMA1[0] > SMA1[0]) && (firstretrace == true) || (secondretrace == true) && (Stochastics2.D[0] < 50) && ((Stochastics2.K[1] < 20) || (Stochastics2.D[2] < 20)) && (Close[0] > SMA1[0])) { EnterLong(Convert.ToInt32(DefaultQuantity), @"Long"); firstretrace = false; secondretrace= false; } }
Comment