Replies

john_7ko
29 Nov 2020, 10:23

RE:

PanagiotisCharalampous said:

Hi john_7ko,

Yes this is correct. To achieve this you will need to code your own stop loss logic that will run in OnBar() method.

Best Regards,

Panagiotis 

Join us on Telegram

 

Is there a way to easily disable all stop losses and then re-enable them while conserving stop loss levels  every time Time.Seconds == 0?


@john_7ko

john_7ko
06 Jul 2020, 14:41

RE:

PanagiotisCharalampous said:

Hi Yuval,

Yes multisymbol backtesting. You can see an example below

using System;
using System.Linq;
using System.Text;
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 MultisymbolBacktesting : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        public Symbol[] MySymbols;

        protected override void OnStart()
        {
            // We get a symbol array for the following for symbols
            MySymbols = Symbols.GetSymbols("EURUSD", "GBPUSD", "USDJPY", "USDCHF");
            // We subscribe to the tick event for each symbol
            foreach (var symbol in MySymbols)
            {
                symbol.Tick += Symbol_Tick;
            }
            // We subscribe to the bar event for each symbol for the current timeframe
            foreach (var symbol in MySymbols)
            {
                var bars = MarketData.GetBars(TimeFrame, symbol.Name);
                bars.BarOpened += Bars_BarOpened;
            }
        }

        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            // When a bar opens we check the previous bar. If the bar is bullish, we send a buy order, else we send a sell order.
            if (obj.Bars.Last(1).Close > obj.Bars.Last(1).Open)
            {
                ExecuteMarketOrder(TradeType.Buy, obj.Bars.SymbolName, 1000, "", 2, 2);
            }
            else
            {
                ExecuteMarketOrder(TradeType.Sell, obj.Bars.SymbolName, 1000, "", 2, 2);
            }
        }

        private void Symbol_Tick(SymbolTickEventArgs obj)
        {
            // On each symbol tick, we print the symbol's bid/ask prices on the chart
            var sb = new StringBuilder();
            foreach (var symbol in MySymbols)
            {
                var textLine = string.Format("{0} {1} {2}", symbol.Name, symbol.Bid, symbol.Ask);
                sb.AppendLine(textLine);
            }
            Chart.DrawStaticText("symbols", sb.ToString(), VerticalAlignment.Top, HorizontalAlignment.Left, Chart.ColorSettings.ForegroundColor);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 

 

 

How does the subscribing process work? I don't understand how it's able to keep triggering the symbol_tick function on each new tick if onstart() is only executed once when the bot starts up.


@john_7ko

john_7ko
26 May 2020, 10:00

RE: RE: RE:

how do you get the "#8fb300" number? 


@john_7ko

john_7ko
18 May 2020, 14:45

RE:

PanagiotisCharalampous said:

Hi John,

No there isn't. You need to check if the change occurred on Bid or on Ask price.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

I thought I had just thought of a way I could do it before reading your post. 

Could you tell me why this wouldn't work: Calculate function executes on each new tick, therefore couldn't you just

check to see if the close price of the 1 tick chart bar changed during that tick, and if not then that means it's an ask tick? and vice versa 


@john_7ko