hascrossed

Created at 10 Feb 2018, 08:55
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!
DO

dordkash@gmail.com

Joined 30.09.2017

hascrossed
10 Feb 2018, 08:55


Hello

I want to say my bot :

if (current price went up one pip from high of last bar) ,do some things

How do i write it​

Thankful​


@dordkash@gmail.com
Replies

PanagiotisCharalampous
12 Feb 2018, 11:12

Hi dordkash@gmail.com,

Let me know if this works for you

            if (Symbol.Bid - MarketSeries.High.LastValue > Symbol.PipSize)
            {
                // Do something
            }

Best Regards,

Panagiotis


@PanagiotisCharalampous

dordkash@gmail.com
13 Feb 2018, 07:26

RE:

Panagiotis Charalampous said:

Hi dordkash@gmail.com,

Let me know if this works for you

            if (Symbol.Bid - MarketSeries.High.LastValue > Symbol.PipSize)
            {
                // Do something
            }

Best Regards,

Panagiotis

Hi dear Panagiotis

When i add this line to my bot

my bot dont take any Buy position


@dordkash@gmail.com

PanagiotisCharalampous
13 Feb 2018, 10:15

Hi dordkash@gmail.com,

Can you share your cBot code? Also please provide some more information on what the cBot is supposed to do.

Best Regards,

Panagiotis


@PanagiotisCharalampous

dordkash@gmail.com
13 Feb 2018, 21:45

RE:
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 kg : Robot
    {
        const string label = "kg";
        private double slb;
        private double sls;


        [Parameter(DefaultValue = 1000)]
        public int VOL { get; set; }
        [Parameter(DefaultValue = 20)]
        public double tp { get; set; }


        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            slb = MarketSeries.Low.Last(1) - Symbol.PipSize * 5;
            var buypips = Math.Round((Symbol.Ask - slb) / Symbol.PipSize);
            var ch = MarketSeries.High.Last(1) - MarketSeries.Close.Last(1);
            var ol = MarketSeries.Open.Last(1) - MarketSeries.Low.Last(1);
            if (...............................)
                if (...................................)
                    if (......................................)

                        if (.............................................)
                            if (..............................................)
                                if (.................................................)
                                    if (....................................................)
                                        if (Symbol.Bid - MarketSeries.High.Last(1) > Symbol.PipSize)


                                            ExecuteMarketOrder(TradeType.Buy, Symbol, VOL, label, buypips, tp);

            sls = MarketSeries.High.Last(1) + Symbol.PipSize * 5;
            var sellpips = Math.Round((sls - Symbol.Bid) / Symbol.PipSize);

            if (.........................)
                if (..........................)
                    if (.............................)
                        if (..............................)
                            if (..................................)
                                if (..................................)
                                    if (......................................)

                                        ExecuteMarketOrder(TradeType.Sell, Symbol, VOL, label, sellpips, tp);



        }

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

Panagiotis Charalampous said:

Hi dordkash@gmail.com,

Can you share your cBot code? Also please provide some more information on what the cBot is supposed to do.

Best Regards,

Panagiotis

 


@dordkash@gmail.com

PanagiotisCharalampous
14 Feb 2018, 11:04

Hi dordkash@gmail.com,

Your code is located in the OnBar method. It is highly unlikely that the bid price will become higher by one pip from the previous high. Maybe you would like to reconsided your logic.

Best Regards,

Panagiotis


@PanagiotisCharalampous

dordkash@gmail.com
15 Feb 2018, 08:56

RE:

Panagiotis Charalampous said:

Hi dordkash@gmail.com,

Your code is located in the OnBar method. It is highly unlikely that the bid price will become higher by one pip from the previous high. Maybe you would like to reconsided your logic.

Best Regards,

Panagiotis

I dont understand

Please explain me more

Best Regards,


@dordkash@gmail.com

... Deleted by UFO ...

PanagiotisCharalampous
15 Feb 2018, 10:13

Hi dordkash@gmail.com,

You have the following condition in OnBar()?

 

if (Symbol.Bid - MarketSeries.High.Last(1) > Symbol.PipSize)
    ExecuteMarketOrder(TradeType.Buy, Symbol, VOL, label, buypips, tp);

This code is executed as soon as a bar closes and a new one is created. This means that the first tick of the new bar should be 1 pip higher that the highest price of the last bar. Ever if the last tick of the previous bar was the highest price recorded for that bar, it is very unlikely that the first tick of the new bar will be 1 pip higher.

Best Regards,

Panagiotis 


@PanagiotisCharalampous

dordkash@gmail.com
15 Feb 2018, 13:05

RE:

Panagiotis Charalampous said:

Hi dordkash@gmail.com,

You have the following condition in OnBar()?

 

if (Symbol.Bid - MarketSeries.High.Last(1) > Symbol.PipSize)
    ExecuteMarketOrder(TradeType.Buy, Symbol, VOL, label, buypips, tp);

This code is executed as soon as a bar closes and a new one is created. This means that the first tick of the new bar should be 1 pip higher that the highest price of the last bar. Ever if the last tick of the previous bar was the highest price recorded for that bar, it is very unlikely that the first tick of the new bar will be 1 pip higher.

Best Regards,

Panagiotis 

Ok

Thank you for your help

What is your solution?

How do i do it


@dordkash@gmail.com

PanagiotisCharalampous
15 Feb 2018, 14:29

Hi dordkash@gmail.com,

Consider putting your logic in the OnTick()  function instead of in the OnBar().

Best Regards,

Panagiotis


@PanagiotisCharalampous

dordkash@gmail.com
15 Feb 2018, 14:44

RE:

Panagiotis Charalampous said:

Hi dordkash@gmail.com,

Consider putting your logic in the OnTick()  function instead of in the OnBar().

Best Regards,

Panagiotis

In this case my bot open position in every tick


@dordkash@gmail.com

PanagiotisCharalampous
15 Feb 2018, 16:00

Hi dordkash@gmail.com,

You can use a boolean flag that will be reset on each OnBar() 

Best Regards,

Panagiotis


@PanagiotisCharalampous