Skip to content

Commit

Permalink
Fixed bugd
Browse files Browse the repository at this point in the history
  • Loading branch information
archReactor04 committed Feb 2, 2024
1 parent 306128a commit 33875f9
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
81 changes: 81 additions & 0 deletions Strategies/ArchReactor/AR_gbrm_CL_BB_MACD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#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.ArchReactor
{
public class AR_gbrm_CL_BB_MACD : ArchReactorAlgoBase
{
private Bollinger Bollinger1;
private MACD MACD1;
protected override void OnStateChange()
{
base.OnStateChange();

if (State == State.SetDefaults)
{
Description = @"This is a strategy by user gbrm to be used in 5 min CL.";
Name = "AR_gbrm_CL_BB_MACD";
StrategyName = "AR_gbrm_CL_BB_MACD";
Credits = "Strategy provided by discord user gbrm";
}
}

protected override void OnBarUpdate()
{
base.OnBarUpdate();
}

#region Strategy Management
protected override void initializeIndicators() {
Bollinger1 = Bollinger(2, 20);
AddChartIndicator(Bollinger1);

MACD1 = MACD(12, 26, 9);
AddChartIndicator(MACD1);

}

protected override bool validateEntryLong() {
if (Open[0] < Bollinger1.Middle[0]
&& Close[0] > Bollinger1.Middle[0]
&& MACD1.Diff[0] > 0){
return true;
}
return false;
}

protected override bool validateEntryShort() {
if (Open[0] > Bollinger1.Middle[0]
&& Close[0] < Bollinger1.Middle[0]
&& MACD1.Diff[0] < 0){
return true;
}
return false;
}

#endregion
}
}

15 changes: 9 additions & 6 deletions Strategies/ArchReactor/ArchReactorAlgoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ abstract public class ArchReactorAlgoBase : Strategy, ICustomTypeDescriptor {
private int Session4Count;
private int SessionNumber;
private bool isPnlAchieved;
private bool ManuallyDisabled = false;

protected override void OnStateChange() {
switch (State) {
case State.SetDefaults:
Description = @"ArchReactorAlgoBase";
Name = "ArchReactorAlgoBase";
BaseAlgoVersion = "1.5";
BaseAlgoVersion = "1.6";
StrategyVersion = "1.0";
Author = "archReactor";
Credits = "archReactor";
Expand Down Expand Up @@ -336,6 +337,7 @@ protected void Button1Click(object sender, RoutedEventArgs e)
button.Background = Brushes.Gray;
button.BorderBrush = Brushes.Black;
IsStratEnabled = false;
ManuallyDisabled = true;
return;
}

Expand All @@ -345,7 +347,8 @@ protected void Button1Click(object sender, RoutedEventArgs e)
button.Name = "StrategyButtonEnabled";
button.Background = Brushes.Aquamarine;
button.BorderBrush = Brushes.Black;
IsStratEnabled = true;
IsStratEnabled = true;
ManuallyDisabled = false;
return;
}
//Draw.TextFixed(this, "infobox", "Button 1 Clicked", TextPosition.BottomLeft, Brushes.Green, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Transparent, Brushes.Transparent, 100);
Expand Down Expand Up @@ -769,7 +772,8 @@ protected bool validateTimeControlsAndTradeCount() {
&& Times[0][0].TimeOfDay <= Stop_Time_1.TimeOfDay
&& Session1Count < MaxTradesPerSession) {
SessionNumber = 1;
return true;
return true;

}
if (Time_2 == true
&& Times[0][0].TimeOfDay >= Start_Time_2.TimeOfDay
Expand Down Expand Up @@ -848,12 +852,11 @@ private void validateStrategyPnl() {

private void validateMaxTradesPerSession() {
if (State == State.Realtime) {
if (isPnlAchieved == false) {
if (isPnlAchieved == false && ManuallyDisabled == false) {
if (Time_1 == true
&& Times[0][0].TimeOfDay >= Start_Time_1.TimeOfDay
&& Times[0][0].TimeOfDay <= Stop_Time_1.TimeOfDay
&& Session1Count < MaxTradesPerSession) {

&& Session1Count < MaxTradesPerSession) {
enableDisableStrat(true);
}
else if (Time_2 == true
Expand Down

0 comments on commit 33875f9

Please sign in to comment.