Skip to content

Commit

Permalink
Update ArchReactorAlgoBase.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
archReactor04 committed Apr 5, 2024
1 parent a1b96a0 commit dcea162
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions Strategies/ArchReactor/ArchReactorAlgoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,34 +756,28 @@ protected virtual bool validateExitShort() {

protected virtual void addDataSeries() {}

protected bool isCustomStopSet() {
if (stopLossType == CommonEnums.StopLossType.Custom) {
return true;
}
protected virtual bool isCustomStopSet() {
return false;
}

protected bool isCustomProfitSet() {
if (profitTargetType == CommonEnums.ProfitTargetType.Custom) {
return true;
}
protected virtual bool isCustomProfitSet() {
return false;
}

protected virtual double customStopLong() {
return Low[0];
return -1;
}

protected virtual double customStopShort() {
return High[0];
return -1;
}

protected virtual double customProfitTargetLong(double price) {
return price + ProfitTargetLong*TickSize;
return -1;
}

protected virtual double customProfitTargetShort(double price) {
return price - ProfitTargetShort*TickSize;
return -1;
}


Expand Down Expand Up @@ -938,7 +932,6 @@ private bool validateStrategytPnlConditions() {
protected virtual void calculateStopLossPriceLong(double price, bool isRunner) {
if (isCustomStopSet() == false) {
if (stopLossType == CommonEnums.StopLossType.ATR) {
//previousPrice = StopLoss_ATR.TrailingStopLow[0];
//SetStopLoss(entryLongString1, CalculationMode.Price, StopLoss_ATR.TrailingStopLow[0], false);
Print("Setting ATR StopLoss Long "+StopLoss_ATR.TrailingStopLow[0]);
if (isRunner == false)
Expand All @@ -949,7 +942,6 @@ protected virtual void calculateStopLossPriceLong(double price, bool isRunner) {
// Print("Put StopLoss 2 ATR Long");
}
} else if (stopLossType == CommonEnums.StopLossType.Fixed){
// previousPrice = price - InitialStopLong*TickSize;
Print("Setting Fixed StopLoss Long "+(price - InitialStopLong*TickSize));
//SetStopLoss(entryLongString1, CalculationMode.Ticks, InitialStopLong, false);
if (isRunner == false)
Expand All @@ -963,7 +955,6 @@ protected virtual void calculateStopLossPriceLong(double price, bool isRunner) {
}
} else {
double stopLossLong = customStopLong();
//previousPrice = stopLossLong;
Print ("Setting Custom Stop Loss Long");

if (isRunner == false)
Expand All @@ -981,7 +972,6 @@ protected virtual void calculateStopLossPriceShort(double price, bool isRunner)
if (isCustomStopSet() == false) {
if (stopLossType == CommonEnums.StopLossType.ATR) {
Print("Setting ATR StopLoss Short "+StopLoss_ATR.TrailingStopHigh[0]);
// previousPrice = StopLoss_ATR.TrailingStopHigh[0];
//SetStopLoss(entryShortString1, CalculationMode.Price, StopLoss_ATR.TrailingStopHigh[0], false);
if (isRunner == false)
ExitShortStopMarket(0, true, PositionSize, StopLoss_ATR.TrailingStopHigh[0], "Stop " + entryShortString1, entryShortString1);
Expand All @@ -994,7 +984,6 @@ protected virtual void calculateStopLossPriceShort(double price, bool isRunner)
}
} else {
Print("Setting Fixed StopLoss Short "+(price + InitialStopLong*TickSize));
// previousPrice = price + InitialStopShort*TickSize;
//SetStopLoss(entryShortString1, CalculationMode.Ticks, InitialStopShort, false);
if (isRunner == false)
ExitShortStopMarket(0, true, PositionSize, (price + InitialStopShort*TickSize), "Stop " + entryShortString1, entryShortString1);
Expand All @@ -1008,7 +997,7 @@ protected virtual void calculateStopLossPriceShort(double price, bool isRunner)
} else {
double stopLossShort = customStopShort();
Print ("Setting Custom Stop Loss Short");
// previousPrice = stopLossShort;
if (isRunner == false)
ExitShortStopMarket(0, true, PositionSize, stopLossShort, "Stop " + entryShortString1, entryShortString1);
else {
Expand Down Expand Up @@ -1154,9 +1143,8 @@ protected virtual void calculateTrailStopAndBE() {
if (trailStopType == CommonEnums.TrailStopType.TickTrail) {
newPrice = previousPrice + TrailStepTicks * TickSize; // Calculate trail stop adjustment
} else if (trailStopType == CommonEnums.TrailStopType.ATRTrail) {
newPrice = (previousPrice < TrailStop_ATR.TrailingStopLow[0]) ? TrailStop_ATR.TrailingStopLow[0] : previousPrice;
//newPrice = TrailStop_ATR.TrailingStopLow[0];

//newPrice = (previousPrice < TrailStop_ATR.TrailingStopLow[0]) ? TrailStop_ATR.TrailingStopLow[0] : previousPrice;
newPrice = TrailStop_ATR.TrailingStopLow[0];
} else if (trailStopType == CommonEnums.TrailStopType.BarTrail && newPrice < Low[TrailByBars]) {
newPrice = Low[TrailByBars];
}
Expand All @@ -1179,8 +1167,8 @@ protected virtual void calculateTrailStopAndBE() {
if (trailStopType == CommonEnums.TrailStopType.TickTrail) {
newPrice = previousPrice + TrailStepTicks * TickSize; // Calculate trail stop adjustment
} else if (trailStopType == CommonEnums.TrailStopType.ATRTrail) {
newPrice = (previousPrice < TrailStop_ATR.TrailingStopLow[0]) ? TrailStop_ATR.TrailingStopLow[0] : previousPrice;
//newPrice = TrailStop_ATR.TrailingStopLow[0];
//newPrice = (previousPrice < TrailStop_ATR.TrailingStopLow[0]) ? TrailStop_ATR.TrailingStopLow[0] : previousPrice;
newPrice = TrailStop_ATR.TrailingStopLow[0];
} // Calculate trail stop adjustment
else if (trailStopType == CommonEnums.TrailStopType.BarTrail && newPrice < Low[TrailByBars]) {
newPrice = Low[TrailByBars];
Expand All @@ -1202,6 +1190,7 @@ protected virtual void calculateTrailStopAndBE() {


case MarketPosition.Short:

if (previousPrice == 0)
{
stopPlot = Position.AveragePrice + InitialStopShort * TickSize; // initial stop plot level
Expand All @@ -1211,7 +1200,6 @@ protected virtual void calculateTrailStopAndBE() {
// Once the price is Less than entry price - breakEvenTicks ticks, set stop loss to breakeven
if (Close[0] < Position.AveragePrice - BreakevenTicks * TickSize && previousPrice == 0)
{

initialBreakEven = Position.AveragePrice - PlusBreakeven * TickSize;
// SetStopLoss(entryShortString1, CalculationMode.Price, initialBreakEven, false);
ExitShortStopMarket(0, true, PositionSize, initialBreakEven, "Stop " + entryShortString1, entryShortString1);
Expand All @@ -1230,8 +1218,8 @@ protected virtual void calculateTrailStopAndBE() {
if (trailStopType == CommonEnums.TrailStopType.TickTrail) {
newPrice = previousPrice - TrailStepTicks * TickSize;
} else if (trailStopType == CommonEnums.TrailStopType.ATRTrail) {
newPrice = (previousPrice > TrailStop_ATR.TrailingStopHigh[0]) ? TrailStop_ATR.TrailingStopHigh[0] : previousPrice;
//newPrice = TrailStop_ATR.TrailingStopHigh[0];
//newPrice = (previousPrice > TrailStop_ATR.TrailingStopHigh[0]) ? TrailStop_ATR.TrailingStopHigh[0] : previousPrice;
newPrice = TrailStop_ATR.TrailingStopHigh[0];
} else if (trailStopType == CommonEnums.TrailStopType.BarTrail && newPrice > High[TrailByBars]) {
newPrice = High[TrailByBars];
}
Expand All @@ -1255,7 +1243,7 @@ protected virtual void calculateTrailStopAndBE() {
newPrice = previousPrice - TrailStepTicks * TickSize;
} else if (trailStopType == CommonEnums.TrailStopType.ATRTrail) {
newPrice = (previousPrice > TrailStop_ATR.TrailingStopHigh[0]) ? TrailStop_ATR.TrailingStopHigh[0] : previousPrice;
//newPrice = TrailStop_ATR.TrailingStopHigh[0];
newPrice = TrailStop_ATR.TrailingStopHigh[0];
} else if (trailStopType == CommonEnums.TrailStopType.BarTrail && newPrice > High[TrailByBars]) {
newPrice = High[TrailByBars];
}
Expand Down Expand Up @@ -1765,9 +1753,6 @@ public CommonEnums.StopLossType StopLossType
} else if (stopLossType == CommonEnums.StopLossType.ATR) {
showFixedStopLossOptions = false;
showATRStopLossOptions = true;
} else if (stopLossType == CommonEnums.StopLossType.Custom) {
showFixedStopLossOptions = false;
showATRStopLossOptions = false;
}
}
}
Expand Down Expand Up @@ -1811,9 +1796,6 @@ public CommonEnums.ProfitTargetType ProfitTargetType
} else if (profitTargetType == CommonEnums.ProfitTargetType.ATR) {
showFixedProfitTargetOptions = false;
showATRProfitTargetOptions = true;
} else if (profitTargetType == CommonEnums.ProfitTargetType.Custom) {
showFixedProfitTargetOptions = false;
showATRProfitTargetOptions = false;
}
}
}
Expand Down

0 comments on commit dcea162

Please sign in to comment.