Can't use Aroon or DMA for buy and sell logic

Created at 28 Aug 2023, 17:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!

Can't use Aroon or DMA for buy and sell logic
28 Aug 2023, 17:04


UPDATE to my question. 

I think I fixed it..

But I think I only fixed the ADX - Directional Movement System logic in my cBot. At least both buy and sell positions are opening

I guess I had to use ADX Period and ADX threshthreshold. I just need to add DIPlus and DIMinus now if that's even possible.

 Can someone help me fix the Aroon logic too?

 

[Parameter("ADX Period", Group = "Directional Movement System", DefaultValue = 20)]
        public int AdxPeriod { get; set; }

        [Parameter("ADX Threshold", Group = "Directional Movement System", DefaultValue = 25)]
        public double AdxThreshold { get; set; }

 

private DirectionalMovementSystem _directionalMovementSystem;

_directionalMovementSystem = Indicators.DirectionalMovementSystem(AdxPeriod);

 

// BUY SIGNAL

X_Oversold && _directionalMovementSystem.ADX.Last(1) >= AdxThreshold)

 


Hi

Did anyone try to use the Directional Movement System or Aroon in their cBots?
 

It won't allow me to have the logic for both buy and sell signal. It won't open any trades.

But when I only use it in the sell logic or only in the buy logic the cBot will open new positions but only buy or sell trades. Why is that?

(I only want to use the Aroon or the Directional Movement System for opening new positions. For closing the positions, I am using a different logic.)

I tried with different approaches..

 

cTrader team, Panagiotis Charalampous please advise.  Or anyone else with some experience.

AROON

[Parameter("Use Aroon Indicator", DefaultValue = true, Group = "AROON")]
        public bool UseAroonIndicator { get; set; }

        [Parameter("Aroon Period", DefaultValue = 10, Group = "AROON" )]
        public int AroonPeriod { get; set; }

private Aroon aroon;

aroon = Indicators.Aroon(AroonPeriod);

var currentAroonUp = aroon.Up.LastValue;
var currentAroonDown = aroon.Down.LastValue;

1. example (I'm using the Aroon together with other indicators in the buy and sell signal)

// Buy signal 

 (UseAroonIndicator && aroon.Up.Last(0) > 90 && aroon.Down.Last(0) < 10))

 

// Sell signal

  (UseAroonIndicator && aroon.Up.Last(0) < 10 && aroon.Down.Last(0) > 90))

 

 

2. example

// Buy signal

{
    if (!UseAroonIndicator || (UseAroonIndicator && aroon.Up.Last(0) == 100 && aroon.Down.Last(0) == 0))

// Sell signal

{
   if (!UseAroonIndicator || (UseAroonIndicator && aroon.Up.Last(0) == 0 && aroon.Down.Last(0) == 100))

 

*********

In this example, only sell position are open. The bot will  only open a few buy positions. The difference is huge. It can open 500 sell and  only 4 buy positions) 

Directional Movement system. (I'm using it together with other indicators) 

[Parameter("DMA Period", Group = "Directional Movement System", DefaultValue = 14)]
        public int DmaPeriod { get; set; }

private DirectionalMovementSystem dma;

dma = Indicators.DirectionalMovementSystem(DmaPeriod);

var isDmaUp = dma.DIPlus.Last(1) > dma.DIMinus.Last(1) && dma.DIPlus.Last(2) <= dma.DIMinus.Last(2);

 

// Buy signal
             X_Oversold && isDmaUp

 

// Sell signal
            X_Overbought && !isDmaUp

 

 


@algorithmic.trading.eu_gmail.com
Replies

firemyst
30 Aug 2023, 07:59

You'd have a better chance of a response if you post more of your code that reproduces the problem.


@firemyst

algorithmic.trading.eu_gmail.com
30 Aug 2023, 17:29

AROON

I tried with different approaches. And when I enable the AROON only sell positions are open, or when I try with a different approach in the source code it won't even open any trades..

Anyone can help me fix this?

1. cBot only opens sell positions!

 [Parameter("Use Aroon Logic", Group = "Aroon Logic", DefaultValue = false)]
public bool UseAroonLogic { get; set; }

[Parameter("Aroon Periods", Group = "Aroon Logic", DefaultValue = 25)]
public int AroonPeriods { get; set; }

[Parameter("Aroon Up Threshold (%)", Group = "Aroon Logic", DefaultValue = 70, MinValue = 0, MaxValue = 100)]
public double AroonUpThresholdPercentage { get; set; }

[Parameter("Aroon Down Threshold (%)", Group = "Aroon Logic", DefaultValue = 30, MinValue = 0, MaxValue = 100)]
public double AroonDownThresholdPercentage { get; set; }

private Aroon _accumulativeSwingIndex;

OnStart

aroon = Indicators.Aroon(AroonPeriods);
            _accumulativeSwingIndex = Indicators.Aroon(AroonPeriods);

 

if (UseAroonLogic)
{
    aroon = Indicators.Aroon(AroonPeriods);
}

 

OnBar

 

   var currentAroonUp = _accumulativeSwingIndex.Up.Last(0);
    var currentAroonDown = _accumulativeSwingIndex.Down.Last(0);
    var previousAroonUp = _accumulativeSwingIndex.Up.Last(1);
    var previousAroonDown = _accumulativeSwingIndex.Down.Last(1);
    
    
    // Calculate the dynamic thresholds based on the Aroon values and user-defined percentages
double aroonUpThreshold = currentAroonUp * (AroonUpThresholdPercentage / 80.0);
double aroonDownThreshold = currentAroonDown * (AroonDownThresholdPercentage / 20.0);

 

BUY

(!UseAroonLogic || (UseAroonLogic && currentAroonUp > aroonUpThreshold && currentAroonDown < aroonDownThreshold))

 

SELL

(!UseAroonLogic || (UseAroonLogic && currentAroonUp > aroonUpThreshold && currentAroonDown < aroonDownThreshold))


 

 2. cBot won't open any positions if I enable the Aroon logic.

 

[Parameter("Use Aroon Logic", Group = "Aroon Logic", DefaultValue = false)]
public bool UseAroonLogic { get; set; }

[Parameter("Aroon Periods", Group = "Aroon Logic", DefaultValue = 25)]
public int AroonPeriods { get; set; }

(thresholds already defined in the OnBar method)

 

private Aroon _accumulativeSwingIndex;

OnStart

if (UseAroonLogic)
{
    aroon = Indicators.Aroon(AroonPeriods);
}

OnBar / OnTick 

// Define the fixed Aroon thresholds for buy and sell signals
const double BuyAroonUpThreshold = 90;
const double BuyAroonDownThreshold = 10;
const double SellAroonUpThreshold = 10;
const double SellAroonDownThreshold = 90;

 

BUY

(!UseAroonLogic || (UseAroonLogic && _accumulativeSwingIndex.Up.Last(0) > BuyAroonUpThreshold && _accumulativeSwingIndex.Down.Last(0) < BuyAroonDownThreshold)) 

SELL

(!UseAroonLogic || (UseAroonLogic && _accumulativeSwingIndex.Up.Last(0) > SellAroonUpThreshold && _accumulativeSwingIndex.Down.Last(0) < SellAroonDownThreshold)) 

 

 

 


@algorithmic.trading.eu_gmail.com