I have a strategy that for all intents and purposes will sell at market when the previous bar closes while the CCI is over 200. I would like to add the converse and buy market when below -200 but i cant even get the first to work.
it will buy the first order and from what I'm seeing it seems to work for the first one as my 1 minute chart shows every market open with the CCI over 200 because its just been that way this week. but there's always another sell, on the very next candle close, after every profit trigger or stop loss thereafter all session. its just trading nonstop even when the CCI is below 200 it still triggers a sell regardless. i am going to paste my code below I hope it formats right. also I made my own CCI but its just different colors so any code calling for "MyCCI" should be changed to "CCI" if you want to test it for me and help figure out what's wrong. unless its blatant just by looking at my code and I cant see why.
also "Market Open" is coming up as "Mar****pen" i dont know why but its not that way in my script. thers also not a space but i cant get it to show up otherwise.
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 CaseyCCIUnlocked : Strategy
{
private CCI CCI1;
private CCI CCI2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "CaseyCCIUnlocked";
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;
TakeProfit = 20;
StopLoss = 48;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
AddChartIndicator(MyCCI(20));
SetProfitTarget(@"CaseyCCIUnlocked", CalculationMode.Ticks, TakeProfit);
SetStopLoss(@"CaseyCCIUnlocked", CalculationMode.Ticks, StopLoss, true);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
//Check if regular trading hours
bool mar****pen = ToTime(Time[0]) >= 063000 && ToTime(Time[0]) <= 130000;
double cci20 = MyCCI(20)[0];
/************************************************** ************************************************** ***************************/
if (mar****pen)
{
/*
// Long
if (CrossBelow(CCI(20), -200, 1));
{
//EnterLong(Convert.ToInt32(DefaultQuantity), @"CaseyCCIUnlocked");
EnterLong();
}
*/
// Short
if (CrossAbove(MyCCI(20), 200, 0));
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"CaseyCCIUnlocked");
}
/************************************************** ************************************************** *******************************/
}
// Exit Positions
if(!mar****pen)
{
ExitLong();
ExitShort();
}
}
region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="TakeProfit", Order=1, GroupName="Parameters")]
public int TakeProfit
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="StopLoss", Order=2, GroupName="Parameters")]
public int StopLoss
{ get; set; }
#endregion
}
}

Comment