Trigger order on touch
Trigger order on touch
16 Sep 2019, 18:05
Hi All
I am building an algo / BOT and struiggling to find a command to trigger a market order on touch of an EMA price
From what I can see there only apepars to be hascrossedabove/below function and no function to trigger based on the price of an EMA matching the current market price and as a result triggering an order.
could someone please confirm for me or suggest which function to use
Thanks
Replies
bhavd85
17 Sep 2019, 11:01
RE:
Panagiotis Charalampous said:
Hi Bhavin Dholakia,
Thanks for posting in our forum. Why do you need a special function for this? Current prices can be found in Symbol.Bid and Symbol.Ask and the latest EMA value can be found in the ema.Result.LastValue property. You can use them to make any comparison you like.
Best Regards,
Panagiotis
Hi Panagiotis
thanks for your reply, the above methods do not tell me the direction of the price though (unless i misunderstand how to use them). My strategy needs to generate a trade based on the direction it touched the EMA, example if the EMA is below the current price...the price moves down to touch it it would generate a market buy at the EMA price.
@bhavd85
PanagiotisCharalampous
17 Sep 2019, 12:51
Hi Bhavin Dholakia,
HasCrossedAbove and HasCrossedBelow tell you the direction of crossing. If you want to implement this on a tick based strategy you can compare the value of the ema with the previous and with the current tick. If you clarify what do you need exactly, I can provide you with an example.
Best Regards,
Panagiotis
@PanagiotisCharalampous
bhavd85
17 Sep 2019, 13:29
RE:
Panagiotis Charalampous said:
Hi Bhavin Dholakia,
HasCrossedAbove and HasCrossedBelow tell you the direction of crossing. If you want to implement this on a tick based strategy you can compare the value of the ema with the previous and with the current tick. If you clarify what do you need exactly, I can provide you with an example.
Best Regards,
Panagiotis
Okay here is what i would like my algo to do:
On the pair GBPJPY - Currently trading at 130 with EMA 28 currently at 129.8, I would like the algo to generate a buy order at 129.8 when the market hits that price. The inverse is also true...so if GBPJPY is trading at 129.50 and EMA28 is 130 I would like the algo to generate a sell order at 130 when the market hits that price. I do not want the price to cross over the EMA simply for the bid/ask to hit the price of the EMA and generate a market order in the required direciton
@bhavd85
PanagiotisCharalampous
17 Sep 2019, 14:49
Hi Bhavin Dholakia,
See below an example
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { ExponentialMovingAverage _ema; bool _askBelowPrice; bool _bidAbovePrice; protected override void OnStart() { _ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 28); _askBelowPrice = Symbol.Ask >= _ema.Result.LastValue; _bidAbovePrice = Symbol.Bid <= _ema.Result.LastValue; } protected override void OnTick() { if (Symbol.Ask <= _ema.Result.LastValue) { if (!_askBelowPrice) ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000); _askBelowPrice = true; } else { _askBelowPrice = false; } if (Symbol.Bid >= _ema.Result.LastValue) { if (!_bidAbovePrice) ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000); _bidAbovePrice = true; } else { _bidAbovePrice = false; } } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
17 Sep 2019, 08:14
Hi Bhavin Dholakia,
Thanks for posting in our forum. Why do you need a special function for this? Current prices can be found in Symbol.Bid and Symbol.Ask and the latest EMA value can be found in the ema.Result.LastValue property. You can use them to make any comparison you like.
Best Regards,
Panagiotis
@PanagiotisCharalampous