You can use a flag to achieve this e.g. bool CanTrade. Set it to false when a trade is taken and then set it back to true when a new bar is opened.
Best regards,
Panagiotis
Thanks Panagiotis,
I have attempted the code below, but believe I am missing something as it places multiple trades per bar, but trader per bar after bar is opened. I attempted to limit positions with Positions.Count, but that stops it being placed per bar.
protected override void OnTick() { if (IncludeBreakEven == true) GoToBreakEven();
var Ema1 = _ema1.Result.Last(0); var Ema2 = _ema2.Result.Last(0); var Ema1i = _ema1.Result.Last(2); var Ema2i = _ema2.Result.Last(2); var Ema3 = _ema3.Result.LastValue; var rising = _ema1.Result.IsRising(); var falling = _ema2.Result.IsFalling(); var rising2 = _ema2.Result.IsRising(); var falling2 = _ema1.Result.IsFalling();
var Ema1 = _ema1.Result.Last(0); var Ema2 = _ema2.Result.Last(0); var rising = _ema1.Result.IsRising(); var falling = _ema2.Result.IsFalling(); var rising2 = _ema2.Result.IsRising(); var falling2 = _ema1.Result.IsFalling();
private void CloseSell() { var Ema1 = _ema1.Result.Last(0); var Ema2 = _ema2.Result.Last(0); foreach (var position in Positions) if (Ema1 < Ema2 && position.TradeType == TradeType.Sell)
{ ClosePosition(position); } }
private void CloseBuy() { var Ema1 = _ema1.Result.Last(0); var Ema2 = _ema2.Result.Last(0); foreach (var position in Positions) if (Ema1 > Ema2 && position.TradeType == TradeType.Buy) { ClosePosition(position); } }
Hi Ryan,
The flag needs to be set to false immediately after the order is executed. You seem to set it to false at random positions. Unfortunately I do not have the time to write the entire strategy for you. If you are not able to code this yourself, you can request for professional assistance.
cTrader Copy works using an equity to equity model. Therefore the volume will be proportional to your strategy provider's volume. You cannot chance the volume yourself.
Please send us some troubleshooting info and quote the link to this discussion by pasting a link to this discussion inside the text box before you submit it.
I solved it with cbot and not with the indicator. However, I'm curious to see your solution. If you want I'll attach the code and tell me what you think.
Hi Andrea,
You cannot execute orders through indicators. It needs to be a cBot.
Please explain what exact help to you need. Nobody will do the job for you but we are happy to help you do it yourself
Best regards,
Panagiotis
Hello!
Thank you for your reply. I need to figure out how can I use/reference my code to custom indicators specifically KeltnerChannel ATR (average true range) instead of Keltner Channels (Simple) readily available indicator.
I got the same issue recently. When I would try to use any objects like Trend Line or Fibonacci Fan and etc. it will get out of mouse control when market is ticking but when a symbol stopped or disabled I can draw properly. Using cTrader 4.8.28 on Errante
Hi there,
Could you pleasesend us some troubleshooting information the next time this happens? Please paste a link to this discussion inside the text box before you submit it.
Best regards,
I made a simple indicator that will cause this issue to occur 100% of the times. The line causing the issue is DrawText or drawing anything every tick, if I am drawing something or drawing on the chart window, the object will lose focus as soon as Calculate is invoked on the indicator.
Code below:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{ [Indicator(AccessRights = AccessRights.None, IsOverlay = false)] public class DrawingBug : Indicator { public override void Calculate(int index) { IndicatorArea.RemoveObject("test"); IndicatorArea.DrawText("test", "BUG!!!", Bars.Last().OpenTime, 0, Color.Red); } }}
Hi razor_00,
Thank you, I have forwarded this to the product team for resolution. In the meanwhile, the issue is caused by the RemoveObject method, which in this case is redundant, you don't need to remove an object in order to redraw it. If you remove that line of code, it should fix the problem.
Best regards,
Panagiotis
Thanks for your reply, I will modify my indicator, anyway the remove and draw calls should not call this behaviour, is that correct? Is that going to be fixed in future versions?
Yes that is correct, we will fix this in an upcoming version
PanagiotisCharalampous
15 Jan 2024, 07:58
RE: RE: RE: RE: Open positions per Bar - OnTick
ryan.a.blake said:
Hi Ryan,
The flag needs to be set to false immediately after the order is executed. You seem to set it to false at random positions. Unfortunately I do not have the time to write the entire strategy for you. If you are not able to code this yourself, you can request for professional assistance.
Best regards,
Panagiotis
@PanagiotisCharalampous