Topics
Forum Topics not found
Replies
amusleh
15 Jun 2022, 08:16
Hi,
Check this guide please: https://help.ctrader.com/ctrader-automate/guides/indicators#multiple-timeframes
@amusleh
amusleh
15 Jun 2022, 08:13
Hi,
You can get the distance between two moving averages like this:
var distanceInPips = Math.Abs(_firstMa.Result[index] - _secondMa.Result[index]) / Symbol.PipSize;
if (distanceInPips > 4)
{
// Do something
}
Regarding your second point, you have to define what's an higher high and what's a lower low, then you will be able to code it.
@amusleh
amusleh
15 Jun 2022, 08:09
H,
You can use standard deviation indicator and a multiplier number like Bollinger Bands, example:
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
public class MADeviationBot : Robot
{
[Parameter("Instance Name", DefaultValue = "")]
public string InstanceName { get; set; }
[Parameter("Source")]
public DataSeries SourceSeries { get; set; }
[Parameter("MA Type")]
public MovingAverageType Type { get; set; }
[Parameter("MA Period")]
public int MAPeriod { get; set; }
[Parameter("Stop Loss")]
public int StopLoss { get; set; }
[Parameter("Risk %", MinValue = 0.01, Step = 0.01)]
public double RiskPerTrade { get; set; }
[Parameter("Std Multiplier", DefaultValue = 1)]
public double StdMultiplier { get; set; }
private MovingAverage _ma;
private StandardDeviation _standardDeviation;
protected override void OnStart()
{
_ma = Indicators.MovingAverage(SourceSeries, MAPeriod, Type);
_standardDeviation = Indicators.StandardDeviation(SourceSeries, MAPeriod, Type);
}
protected override void OnBar()
{
int index = Bars.Count - 1;
Entry(index);
Exits(index);
}
private void Entry(int index)
{
if (_ma.Result[index] - Bars.ClosePrices[index] > _standardDeviation.Result[index] * StdMultiplier)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, null);
}
else if (Bars.ClosePrices[index] - _ma.Result[index] > _standardDeviation.Result[index] * StdMultiplier)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, null);
}
}
private void Exits(int index)
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
{
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index] > _ma.Result[index]) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index] < _ma.Result[index]))
{
ClosePosition(position);
}
}
}
private double GetVolume(double? stopLossPips = null)
{
double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;
// Change this to Account.Equity if you want to
double baseNumber = Account.Balance;
double sizeInLots = Math.Round((baseNumber * RiskPerTrade / 100) / (stopLossPips.Value * costPerPip), 1);
var result = Symbol.QuantityToVolumeInUnits(sizeInLots);
return result;
}
}
}
@amusleh
amusleh
15 Jun 2022, 08:00
Hi,
Check here: https://help.ctrader.com/ctrader-automate/guides/indicators#multiple-timeframes
@amusleh
amusleh
14 Jun 2022, 09:40
Hi,
This:
double candle1SizePips = Math.Round(candle1Size / Symbol.PipSize, 3);
Will round the result of "candle1Size / Symbol.PipSize" to three decimal places.
Symbol.PipSize gives you a symbol 1 pip value in absolute price, for example the EURUSD pip size is 0.0001.
Dividing the candle1Size to Symbol.PipSize will give you the exact number of Pips, for example if candle1Size is 0.0008 and the symbol pip size is 0.0001 then:
0.0008 / 0.0001 = 8
@amusleh
amusleh
14 Jun 2022, 09:35
Hi,
Stop Limit order limits the price range that your order can be filled, this is very simple.
When you tested it, was there any instance of getting filled in a worst price than your set limit range?
What kind of difference you are expecting? stop limit order is similar to stop order except it limits the price for filling of your order based on your provided limit range.
@amusleh
amusleh
14 Jun 2022, 09:08
Hi,
I tested it on both cTrader 4.1 and 4.2, it works fine.
The add buttons work fine, and when I changed the chart objects everything worked, no error.
What you did that you got that error? did you developed this indicator? if it's not your indicator then contact the developer and report the issue to him.
@amusleh
amusleh
14 Jun 2022, 08:52
Hi,
Most probably what you are asking for will require more than few lines of code, and the indicator code you pasted lost it's code syntax format.
Please use editor code snippet to post code.
For these kind of tasks you can post a job request or ask one of our consultants.
@amusleh
amusleh
14 Jun 2022, 08:47
Hi,
Detaching and reattaching charts will change the order of charts on cTrader chart container, when you reattach a chart it's appended to the end of container charts.
It was always like this, and this behavior is not changed on 4.2 either.
You can open a thread under suggestion section for this feature to be added.
@amusleh
amusleh
16 Jun 2022, 08:58
Hi,
We were able to reproduce the issue, we will fix this on next release.
Thanks for reporting.
@amusleh