How to apply multiple currencies by one cBot?

Created at 22 Jan 2023, 05:40
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JE

jennifer1978bgf

Joined 22.01.2023

How to apply multiple currencies by one cBot?
22 Jan 2023, 05:40


How to apply multiple currencies by one cBot?

I have tried the code below, even different currencies get opened, the price is not correct.

Can someone help?


        [Parameter("Vol", DefaultValue = 10000)]
        public int Vol { get; set; }

        protected override void OnStart()
        {
            Symbol symbol_1 = MarketData.GetSymbol("USDJPY");
            Symbol symbol_2 = MarketData.GetSymbol("EURUSD");
            Symbol symbol_3 = MarketData.GetSymbol("GBPUSD");

            var result =

            PlaceLimitOrder(TradeType.Buy, symbol_1, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BU", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_2, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BE", 30, 15);           
            PlaceLimitOrder(TradeType.Buy, symbol_3, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BG", 30, 15);           

            if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
        }
    }
}


@jennifer1978bgf
Replies

firemyst
25 Jan 2023, 06:18

RE:

jennifer1978bgf said:

How to apply multiple currencies by one cBot?

I have tried the code below, even different currencies get opened, the price is not correct.

Can someone help?


        [Parameter("Vol", DefaultValue = 10000)]
        public int Vol { get; set; }

        protected override void OnStart()
        {
            Symbol symbol_1 = MarketData.GetSymbol("USDJPY");
            Symbol symbol_2 = MarketData.GetSymbol("EURUSD");
            Symbol symbol_3 = MarketData.GetSymbol("GBPUSD");

            var result =

            PlaceLimitOrder(TradeType.Buy, symbol_1, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BU", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_2, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BE", 30, 15);           
            PlaceLimitOrder(TradeType.Buy, symbol_3, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BG", 30, 15);           

            if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
        }
    }
}

one of your issues is for each of those, you're using the chart's current symbol to get the ask and pipsize, not the currency you want.

Symbol.Ask gets the charts current symbol's asking price.

 

If you want the asking price of USDJPY for example, with your code you have to use symbol_1.Ask and symbol_1.PipSize

 


@firemyst

jennifer1978bgf
25 Jan 2023, 07:05

RE: RE:I have changed symbol_1.Ask and symbol_1.PipSize

firemyst said:

jennifer1978bgf said:

How to apply multiple currencies by one cBot?

I have tried the code below, even different currencies get opened, the price is not correct.

Can someone help?


        [Parameter("Vol", DefaultValue = 10000)]
        public int Vol { get; set; }

        protected override void OnStart()
        {
            Symbol symbol_1 = MarketData.GetSymbol("USDJPY");
            Symbol symbol_2 = MarketData.GetSymbol("EURUSD");
            Symbol symbol_3 = MarketData.GetSymbol("GBPUSD");

            var result =

            PlaceLimitOrder(TradeType.Buy, symbol_1, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BU", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_2, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BE", 30, 15);           
            PlaceLimitOrder(TradeType.Buy, symbol_3, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BG", 30, 15);           

            if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
        }
    }
}

one of your issues is for each of those, you're using the chart's current symbol to get the ask and pipsize, not the currency you want.

Symbol.Ask gets the charts current symbol's asking price.

 

If you want the asking price of USDJPY for example, with your code you have to use symbol_1.Ask and symbol_1.PipSize

 

 


@jennifer1978bgf

jennifer1978bgf
25 Jan 2023, 07:07

RE: RE: RE:I have changed symbol_1.Ask and symbol_1.PipSize and also for symbol2 and 3, but it turn out only the first LimitOrder is pending order, the 2nd and the 3rd was opened as MarketOrder, please help.

jennifer1978bgf said:

firemyst said:

jennifer1978bgf said:

How to apply multiple currencies by one cBot?

I have tried the code below, even different currencies get opened, the price is not correct.

Can someone help?


        [Parameter("Vol", DefaultValue = 10000)]
        public int Vol { get; set; }

        protected override void OnStart()
        {
            Symbol symbol_1 = MarketData.GetSymbol("USDJPY");
            Symbol symbol_2 = MarketData.GetSymbol("EURUSD");
            Symbol symbol_3 = MarketData.GetSymbol("GBPUSD");

            var result =

            PlaceLimitOrder(TradeType.Buy, symbol_1, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BU", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_2, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BE", 30, 15);           
            PlaceLimitOrder(TradeType.Buy, symbol_3, Vol, Symbol.Ask - 15 * Symbol.PipSize, "BG", 30, 15);           

            if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
        }
    }
}

one of your issues is for each of those, you're using the chart's current symbol to get the ask and pipsize, not the currency you want.

Symbol.Ask gets the charts current symbol's asking price.

 

If you want the asking price of USDJPY for example, with your code you have to use symbol_1.Ask and symbol_1.PipSize

 

 

 


@jennifer1978bgf

firemyst
25 Jan 2023, 07:47

How about posting your updated code?


@firemyst

jennifer1978bgf
25 Jan 2023, 08:09

RE: I used the updated code and only the first LinitOrder is PendingOrder, the rest two was opened as MarketOrder.

firemyst said:

How about posting your updated code?

 


@jennifer1978bgf

jennifer1978bgf
25 Jan 2023, 08:10

jennifer1978bgf said:

firemyst said:

How about posting your updated code?

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class UnderTest2 : Robot
    {
        [Parameter(DefaultValue = "USDJPY")]
        public string symbol_1 { get; set; }
        
        [Parameter(DefaultValue = "EURUSD")]
        public string symbol_2 { get; set; }
        
        [Parameter(DefaultValue = "GBPUSD")]
        public string symbol_3 { get; set; }

        [Parameter("Vol", DefaultValue = 10000)]
        public int Vol { get; set; }
        
        public double targetPrice_1 { get; set; }
        public double targetPrice_2 { get; set; }
        public double targetPrice_3 { get; set; }
        
        ///////////////////////////////////////////////////////////////////////////////////////////////

        protected override void OnStart()
        {
            Symbol symbol_1 = MarketData.GetSymbol("USDJPY");
            Symbol symbol_2 = MarketData.GetSymbol("EURUSD");
            Symbol symbol_3 = MarketData.GetSymbol("GBPUSD");

            var result =

            PlaceLimitOrder(TradeType.Buy, symbol_1, Vol, Symbol.Ask - 15 * symbol_1.PipSize, "BU", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_2, Vol, Symbol.Ask - 15 * symbol_2.PipSize, "BE", 30, 15);
            PlaceLimitOrder(TradeType.Buy, symbol_3, Vol, Symbol.Ask - 15 * symbol_3.PipSize, "BG", 30, 15);

            if (!result.IsSuccessful) Print("Error: ", result.Error);
             Stop();
        }
    }
}


@jennifer1978bgf

firemyst
25 Jan 2023, 08:15

You haven't updated the code in all the required places, and are still using Symbol.Ask in places you shouldn't be.

 

:-)


@firemyst

jennifer1978bgf
25 Jan 2023, 08:19

RE: How to update? please help. In fact, my purpose is that no need to add all other instances but still place those LinitOrder in just one click, how to do this?

firemyst said:

You haven't updated the code in all the required places, and are still using Symbol.Ask in places you shouldn't be.

 

:-)

 


@jennifer1978bgf