Topics
Replies
Fron
26 Aug 2021, 03:06
RE: Brotha
amusleh said:
Hi,
You just have to subtract the current price from MA value:
using cAlgo.API; using cAlgo.API.Indicators; using System; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SimpleMovingAverageSample : Robot { private double _volumeInUnits; private SimpleMovingAverage _simpleMovingAverage; [Parameter("Source", Group = "MA")] public DataSeries MaSource { get; set; } [Parameter("Period", DefaultValue = 9, Group = "MA")] public int MaPeriod { get; set; } [Parameter("Volume (Lots)", DefaultValue = 0.01, Group = "Trade")] public double VolumeInLots { get; set; } [Parameter("Stop Loss (Pips)", DefaultValue = 10, Group = "Trade")] public double StopLossInPips { get; set; } [Parameter("Take Profit (Pips)", DefaultValue = 10, Group = "Trade")] public double TakeProfitInPips { get; set; } [Parameter("Label", DefaultValue = "Sample", Group = "Trade")] public string Label { get; set; } public Position[] BotPositions { get { return Positions.FindAll(Label); } } protected override void OnStart() { _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots); _simpleMovingAverage = Indicators.SimpleMovingAverage(MaSource, MaPeriod); } protected override void OnTick() { if (BotPositions.Length > 0) return; var priceDistanceFromMa = Bars.ClosePrices.LastValue - _simpleMovingAverage.Result.LastValue; var priceDistanceFromMaInPips = priceDistanceFromMa * (Symbol.TickSize / Symbol.PipSize * Math.Pow(10, Symbol.Digits)); if (priceDistanceFromMaInPips >= 150) { ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips); } } } }
You are Amazing brotha thank you! Not a pro at Csharp but working on it ! Big Step for me! Realized I need to learn more Math.pow and its works !
@Fron
Fron
25 Aug 2021, 16:46
RE: Yo
amusleh said:
Hi,
Please check the simple moving average example cBot: cAlgo API Reference - SimpleMovingAverage Interface (ctrader.com)
The example cBot opens a buy position if faster MA cross upward the slower MA and a sell position if faster M<A cross downward the slower MA.
If you need something more complicated you can post a job request or ask one of our consultants to develop your cBot.
I have already build serveral bot with crossing MA's I was asking, my question is, what API do i use to trigger a buy in a cbot after its price crosses 150 pips above that MA.
@Fron
Fron
18 Feb 2021, 22:48
RE:
PanagiotisCharalampous said:
Hi Fron,
I am not sure what kind of function are you looking for. This is just a subtraction.
Best Regards,
Panagiotis
I was thinking something like a Gauge like function, it would tell the Percentage of the distance betweeen the two points price and MA, as price draws closer to the other or once it crosses still calculate the differance from price and MA
@Fron
Fron
25 Jan 2021, 21:09
RE:
PanagiotisCharalampous said:
Hi Fron,
Volume data is available in Bar.TickVolume.
Best Regards,
Panagiotis
Thank you!
cheers
@Fron
Fron
18 Dec 2021, 19:40
You are Amazing!!!
Thank you for the christmas Gift!!
@Fron