Topics
Replies

firemyst
13 Mar 2023, 07:29

Would it just be as easy as:

1) set a tickCount variable to zero (0) when your order is successful

2) while in the position, on each "OnTick" event, add 1 to your variable.

3) when the position is closed, save the tick count.

 

??


@firemyst

firemyst
12 Mar 2023, 12:24

It's not very complex.

Doing a Google search, there's a similar one:

 

Perhaps you could contact that author to see if they'd be willing to do it for you.

If not, you should contact @PanagiotisChar

It would also help if you updated your post with the link to the original indicator on TradingView (assuming that's where you got it from since LazyBear is very active there)


@firemyst

firemyst
12 Mar 2023, 04:51

The first question is -- do you want to do this all under the same cBot? Or across different cBots? The answer to that question will affect the way you architecture things (and thus performance), because cBots cannot communicate directly with each other.

 

If it's the former, one thing you could try is setting a static variable that maintains the count. You'd have to make updating that variable thread-safe.

 


@firemyst

firemyst
12 Mar 2023, 04:47

RE:

j_matu said:

Hey there,

I am writing a cBot with two indicators (MACD and EMA)

I want them to run at separate time-frames, for example EMA crossover at H2 and MACD crossover at M5.

Am stuck trying to reference H2 and M5 time-frames.

Any help will be highly appreciated.

Thanks.

Have you looked at any of the code samples Spotware provided?

 

 

 

 


@firemyst

firemyst
12 Mar 2023, 04:41

RE:

Spotware said:

Dear traders, 

Does anyone of you that experience the issue run cTrader on a virtual machine hosted on Linux or an ARM processor?

Best regards,

cTrader Team

@Spotware, see also this thread. Seems to still be happening to people as of March 10, 2023:

 

 


@firemyst

firemyst
10 Mar 2023, 07:41

Can you post a video or link to a video showing this?


@firemyst

firemyst
10 Mar 2023, 07:39

Can you post example C# code which demonstrates the issue through the API?


@firemyst

firemyst
09 Mar 2023, 08:09

RE:

ctid2434759 said:

Hi there,

This code is simplified for solving this specific problem.

I want to check if a position with the Label of "X" has closed.
If it has closed I want to add that into my if statement so that another one doesn't open again.

Something like this?
 if (CheckPositions < 2 && currentSymbolOrderLabel < 1 && PositionClosed.Label = "X" < 1 ) ??

So if there is less than 2 total open positions and less than one of the label "X" and the label "X" position has not already closed then ExecuteMarketRangeOrder.

Aka, if position Label "X" has closed do NOT ExecuteMarketRangeOrder for "X" again..

Thanks
 

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.Robots
{
    [Robot(TimeZone = TimeZones.SingaporeStandardTime, AccessRights = AccessRights.None)]
    public class ClosePositionOnTime : Robot
    
    

    
    {

        // Just the current simulator pairs global variables.
        private double _highPrice;
        private double _lmtPrice;


        protected override void OnStart()
        {

            Positions.Closed += PositionsOnClosed;
            
             // Get the high Price of the last candle for this pair
            _highPrice = Bars.HighPrices.Maximum(2);
            // Then set the price 1 pip bellow that (so i can allow it to act like a LMT order)
            _lmtPrice = _highPrice - 1 * Symbol.PipSize;
            
            // Draw this LMT order or price line on the chart so i can see the entry point.
            var highLine = Chart.DrawHorizontalLine("Low", _lmtPrice, Color.Blue);
            highLine.IsInteractive = true;          
          

            
        }

  
       protected override void OnTick()
       {           
 
            // Get the current Price, which is the symbols previous ASK price.
            // Then inside the onTick method this keeps checking every tick if the ask price is bellow the entry price.
            var _previousAsk = Symbol.Ask;
            
            
            // Check if the current price is higher than the previous ticks ASK price
            if (_lmtPrice != 0 && _previousAsk < _lmtPrice)
            {
            
                //See if there are any Open positions
                var CheckPositions = Positions.Count;    
               
                
                var currentSymbolOrderLabel = Positions.FindAll("X").Length;
                    
                //If "CheckPositions" Reports That less than 2 total positions are open and no existing current order with the label "Current Symbol Order" is open, Then ExecuteMarketOrder

                // HOW DO I ALSO CHECK IF THIS POSITION HAS CLOSED.
                // So if the order with Label "Current Symbol Order" has filled and closed do not fill it again
                // There will be multiple position Labels so it will need to check through the closed positions and find the matching Label
                if (CheckPositions < 2 && currentSymbolOrderLabel < 1 ) {                                 
            
                    // Place a buy order
                    // At the current ask price because its bellow the trigger price with a range of 1 pip.
                    ExecuteMarketRangeOrder(TradeType.Buy, SymbolName, 1000, 1, Symbol.Ask, "X", null, 25);

                }
            
           }
           
               
                
       }
       
       
       // Position Closed event that gets the label.
       private void PositionsOnClosed(PositionClosedEventArgs args)
        {
            var pos = args.Position;
            var label = pos.Label;
            Print("Closed Position: " + label);
        }
       


        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

 

You need to search the Historical Trade object it seems like.

HistoricalTrade ht = History.FindLast(the_label_to_look_for);

 


@firemyst

firemyst
09 Mar 2023, 08:06 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: cTrader ClosePrices.last

deeganpope said:

I am using closeprices.last(0) and still have it trading 2 bars late.  Did you ever figure this out?

 

 

ctid1820873 said:

Hi, I have searched all over and can´t find what I need.

If I use OnBar and Bars.ClosePrices.Last(1) or Bars.LastBar.Close it seems the execution is "On Bar Close" and not "On Bar Open" so as you see on my image the trigger here is the candle close under the line so next candle should execute but it is always the next after that which is too late.

If I use OnTick it triggers as soon as the low goes under the line but it might not close under anyway so that is too soon.

 

How would I go about triggering on the next open after closing under the line?

 

I

Thanks

 

 

Why not try posting some code so people can see what you're doing and why it's possibly not working?


@firemyst

firemyst
09 Mar 2023, 08:02

RE:

Serenityz0926 said:

Hello,
I'm looking for a way to change the height of indicator windows. I can change the height manually from the chart by dragging the top border but i want to do it with code.
I have gone through all the methods but can't seem to find anything.
Is it even possible to change the height of the indicator window?

I don't believe there is


@firemyst

firemyst
09 Mar 2023, 08:00

RE:

ctid5698155 said:

Does Ctrader has a indicator for the rangebar close alert.  

You can try here:

Or do a Google search.

Or write your own to make a sound every time a range bar closes. It won't be too hard. :-)


@firemyst

firemyst
09 Mar 2023, 07:59

RE:

hansenlovefiona said:

 

I want Absolute ATR (ATR%) Indicator, where could i find it?

When it comes to recognizing long-term trends, it could be recommended using Absolute ATR (ATR%) as it will not depend on a price level of an analyzed stock or index. As an example, before 1973 crash the S&P 500 index was traded around $110 and before crash in 2008 the same S&P 500 index was traded around $1500. Such, in the first case the ATR was around 2.3 points and in the second case the ATR was around 30 points. However, in both cases, prior to the crash the Absolute ATR (ATR%) was below 2% and during the crash above 2%. As you may see, the Absolute Average True Range indicator allows comparing different securities and different periods in order to find patterns.

TRy looking here:

 


@firemyst

firemyst
09 Mar 2023, 07:54

Maybe show more of your code so we can see how you're implementing it and what you're setting "Bars" to?

 

For example, you don't say if you're using Chart.Bars.Count or Algo.Bars.Count, which is probably why you're getting the same count -- using the incorrect one in context.


@firemyst

firemyst
09 Mar 2023, 07:50 ( Updated at: 21 Dec 2023, 09:23 )

RE:

amirus.stark said:

Hi there, how can I change the way ctrader handles the hours from the AM/PM system to the 24h system please ?

Mine does 24 by default. Maybe try resetting your chart settings?


@firemyst

firemyst
09 Mar 2023, 03:16

RE:

jaydcrowe1989 said:

Hi,

Is there a way to detect that the instrument you are trading is now outside of the trading hours? When the instruments closes I need to close all of my trades out just before that happens. I am getting trades being left open over the weekends and that is not obviously good when that instrument then opens again for trading.

 

Cheers,

Jay

 

 


@firemyst

firemyst
09 Feb 2023, 09:59

RE: RE: RE:

ctid1531384 said:

firemyst said:

firemyst said:

With API 3.7:

MarketData.GetSeries

is now obsolete, but there's no suggested replacement? How do we now get a different symbol and timeframe's data other than the currently viewed chart? Eg, if I'm viewing the US30 on an M1 chart, and want to get data from the GER30 M1, how do we now do this? It used to be MarketData.GetSeries(_symbol, _timeFrame);

Also, when will the online API guide be updated? I can't find the new "bars" interface in it.

Thank you.

I just found it.

I believe it's now:

MarketData.GetBars(Bars.TimeFrame, _symbol);

However, if I'm wrong or there's something else I should be using, please let me know.

Thanks!

So how do we do it?

All I want is to have the Weekly RSI number there, So i can have 

if (Week RSI > 70)

{dont trade etc

Dont even want it from a different symbol, Just the same one thats on the cbot chart.

 

John.

 

 

Get your Bars / Market Series in the time frame you want, and then create a new Relative Strength Index object with that bars/market series as the first parameter.

Example is right here on this site:

 


@firemyst

firemyst
05 Feb 2023, 15:13

You keep adding to the value of velocity:

 

velocity += distance * K / 100;

 

Every tick you say velocity = velocity + distance * K / 100;

 

You never reset it to another value, so of course it's going to increase into infinity.


@firemyst

firemyst
05 Feb 2023, 12:01 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE:

deeganpope said:

firemyst said:

You're missing a screen capture showing us an example of where you think your bot has gotten in late.

That would be helpful

Here's another example of the trade initiating 1-2 bars after the trigger conditions are met.

 

1) Looks like the exact same screen capture example as your previous post

2) The "sell 5.00 lots" covers up the DEMA so we can't see what it's doing there

3) have you tried putting PRINT statements in front of your conditions to see whether or not each condition is true or false? Or done any debugging in Visual Studio?

 

//Have you tried stuff like this?

Print ("Current Trend {0}", CurrentTrend());
Print ("DEMA.REsult.LastValue {0}, EMA.Result.LastValue {1}, DEMA.Result.LastValue < EMA.Result.LastValue {2}", DEMA.REsult.LastValue, EMA.Result.LastValue, DEMA.Result.LastValue < EMA.Result.LastValue);

//etc 
//etc
//etc
//Now you know what everything is evaluating to, so you can figure out why your "if" statement isn't evaluating the way you expect

 if (CurrentTrend() == "down" && DEMA.Result.LastValue < EMA.Result.LastValue && EMA.Result.LastValue < SMA.Result.LastValue && MACD.MACD.LastValue < MACD.Signal.LastValue && DEMA.Result.IsFalling() && EMA.Result.IsFalling() && SMA.Result.IsFalling() && (shortOpen == false)){

 


@firemyst

firemyst
03 Feb 2023, 03:28 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Spotware said:

Dear firemyst,

Execution issues should be handled by your broker. Please contact your broker regarding this matter.

Best regards,

cTrader Team

 

Hi @Spotware, I've heard back from Pepperstone. Here is what they said and why I believe it's can't be.

 

@Spotware, in regards to "Then you have added 0.1lot  to your existing position at the Ask price of 11640.4 with no protection as you can see it at the screenshot below:", when you modify a position, you CANNOT add an SL to it as it takes on the SL of the current position you're increasing the size of. Screen capture from cTrader as evidence:

 

Even the API call "Position.ModifyVolume()" has no parameter for setting the SL when increasing the volume size of a position.

This has only started happening since the latest 4.6.x releases of cTrader.

So what appears to be happening is cTrader is NOT putting the current SL or TP on new positions when the current position's volume is increased on RENKO charts.

@SPOTWARE / @PanagiotisChar, I think this needs to be investigated further.

 

 

 


@firemyst

firemyst
02 Feb 2023, 14:39

Am pretty sure you can't.

 


@firemyst