Replies

PanagiotisCharalampous
15 Jan 2024, 07:58

RE: RE: RE: RE: Open positions per Bar - OnTick

ryan.a.blake said: 

PanagiotisCharalampous said: 

ryan.a.blake said: 

PanagiotisCharalampous said: 

Hi Ryan,

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. 

 

Have I missed something?

 

Thanks for your help.

 

private bool _canTrade;
private int barCountSinceLastPosition;
        protected override void OnStart()
        {
            _ema1 = Indicators.GetIndicator<SampleEMA>(Source1, Period1);
            _ema2 = Indicators.GetIndicator<SampleEMA>(Source2, Period2);
             _ema3 = Indicators.GetIndicator<SampleEMA>(Source3, Period3);
            _rsi = Indicators.RelativeStrengthIndex(Source3, Period3);
           
           Bars.BarOpened += Bar_Opened;
         }
        
           void Bar_Opened(BarOpenedEventArgs args)
                   {
                      _canTrade = false;
            
                   }
        
         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();
                          
             if (Ema1 > Ema2 && falling && falling2 && Symbol.Bid == Bars.OpenPrices.Last(0) - (pips * Symbol.PipSize))
            {
                
                   if (Positions.Count(x => x.TradeType == TradeType.Sell && x.Label == InstanceName) == 0)
                
                         {
                               double volume = Symbol.QuantityToVolumeInUnits(lotsize);
                               ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, InstanceName, SL, TP);
                
                           }
                               {
                                  _canTrade = true;
                               }
                                    if(_canTrade)
                                    {
                                        if (Ema1 > Ema2 && falling && falling2 && Symbol.Bid == Bars.OpenPrices.Last(0) - (pips * Symbol.PipSize))
                                         {
                                             double volume = Symbol.QuantityToVolumeInUnits(lotsize);
                                             ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, InstanceName, SL, TP);
                                         }
                                   }
                              }
                          {
                    CloseSell();
                     } 
                    
               }

Hi Ryan,

_canTrade needs to be set to false in OnTick() and to true in OnBar()

Best regards,

Panagiotis

Thanks Panagiotis,

Could you share an example code for this? 

I have added OnBar() but multiple trades are still opening. Have I placed everything correctly? 

    private SampleEMA _ema1 { get; set; }
        private SampleEMA _ema2 { get; set; }
         private SampleEMA _ema3 { get; set; }
        private RelativeStrengthIndex _rsi { get; set; }

private bool _canBuy;
 private bool _canSell;

        protected override void OnStart()
        {

            _ema1 = Indicators.GetIndicator<SampleEMA>(Source1, Period1);
            _ema2 = Indicators.GetIndicator<SampleEMA>(Source2, Period2);
             _ema3 = Indicators.GetIndicator<SampleEMA>(Source3, Period3);
            _rsi = Indicators.RelativeStrengthIndex(Source3, Period3);
      
        }            
                
protected override void OnBar()
               
               {
            _canSell = true;       
               }
               
         protected override void OnTick()
        {
        Print("OnTick");
        
     
           if (IncludeBreakEven == true)
                GoToBreakEven();
               

            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();
                    
             if (Ema1 < Ema2 && rising && rising2 && Symbol.Bid == Bars.OpenPrices.Last(0) + (pips * Symbol.PipSize))
              
            {
                _canBuy = false;
            }
                            
                     {
                      CloseBuy();
                      }
                      
                      
             
             if (Ema1 > Ema2 && falling && falling2 && Symbol.Bid == Bars.OpenPrices.Last(0) - (pips * Symbol.PipSize))
            {           
                   
                  double volume = Symbol.QuantityToVolumeInUnits(lotsize);
                ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, InstanceName, SL, TP);
                }
                
                
                if(_canSell == true)
                 
                {
            if (Positions.Count(x => x.TradeType == TradeType.Sell && x.Label == InstanceName) >= 2)
            {
            _canSell = false;
             
               
                }
             
               }
               {
                    CloseSell();
                }
               
               }
                        
 
               
        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.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
15 Jan 2024, 07:52

Hi there,

This is not possible at the moment however the team is considering this.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
15 Jan 2024, 07:41

RE: RE: MarketData.GetBars hangs forever

Intetics said: 

PanagiotisCharalampous said: 

Hi there,

Thanks for the information, we will investigate it

Best regards,

Panagiotis

HI PanagiotisCharalampous,

Did you guys manage to reproduce the issue?

Regards

Hi there,

Yes and we are working on a solution.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
13 Jan 2024, 08:03

Hi there,

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.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
13 Jan 2024, 08:00

Hi there,

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.

Best Regards,

Panagiotis 


 


@PanagiotisCharalampous

PanagiotisCharalampous
13 Jan 2024, 07:58

Hi Andrea,

You can use Convert.ToDouble() method.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
13 Jan 2024, 07:56

RE: RE: Button event

AndreaPereira said: 

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.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 13:02

Hi again,

It seems your broker does not offer this service. Please contact your broker instead.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 12:51

RE: Same problem

dan.kelly654 said: 

Hello,

I've been having the same problem for the last few days:

What was the fix?

Thanks

Hi there,

Can you please send us troubleshooting information as requested above?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 12:48

RE: RE: ctrader desktop vs ctrader tablet

valepi said: 

PanagiotisCharalampous said: 

Hi there,

Can you please advise your broker and share some screenshots?

Best regards,

Panagiotis

 

Hi valepi,

Thanks but you haven't shared your broker


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 12:47

RE: RE: How to use custome indicator in CBOt?

lfdomingo143 said: 

PanagiotisCharalampous said: 

Hi there, 

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.

Hi again,

Check the video below, it should be helpful


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 12:44

Hi Andrea,

Can you share your complete cBot code?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:29

Hi there, 

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


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:27

Hi there,

Can you please advise your broker and share some screenshots?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:26

Responded here

https://ctrader.com/forum/ctrader-support/42682#post-106805


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:25

Hi there,

Make sure that you use the .Net 6.0 compiler to build your cBots


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:23

Hi there,

Can you please advise your broker, the symbol you are using and share some screenshots as well?

Best regards,

 


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:20 ( Updated at: 12 Jan 2024, 07:21 )

Hi there,

Thanks for the information, we will investigate it

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:19

Hi there,

Can you please explain to us how we can reproduce this behavior? Screenshots and videos would be helpful.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
12 Jan 2024, 07:18

RE: RE: RE: RE: RE: Draw issue

razor_00 said: 

PanagiotisCharalampous said: 

razor_00 said: 

PanagiotisCharalampous said: 

GOLDEN.DRAGONS said: 

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 please send 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