hascrossed

10 Feb 2018, 08:55hascrossed#1
dordkash@gmail.composts: 33since: 30 Sep 2017

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​

12 Feb 2018, 11:12#2
Panagiotis Charalampousposts: 1200since: 13 Jan 2017

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


Head of Community Management at cTrader
13 Feb 2018, 07:26RE:#3
dordkash@gmail.composts: 33since: 30 Sep 2017

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

13 Feb 2018, 10:15#4
Panagiotis Charalampousposts: 1200since: 13 Jan 2017

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


Head of Community Management at cTrader
13 Feb 2018, 21:45RE:#5
dordkash@gmail.composts: 33since: 30 Sep 2017
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

 

14 Feb 2018, 11:04#6
Panagiotis Charalampousposts: 1200since: 13 Jan 2017

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


Head of Community Management at cTrader
15 Feb 2018, 08:56RE:#7
dordkash@gmail.composts: 33since: 30 Sep 2017

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,

15 Feb 2018, 10:13#8
Panagiotis Charalampousposts: 1200since: 13 Jan 2017

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 


Head of Community Management at cTrader
15 Feb 2018, 13:05RE:#9
dordkash@gmail.composts: 33since: 30 Sep 2017

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

15 Feb 2018, 14:29#10
Panagiotis Charalampousposts: 1200since: 13 Jan 2017

Hi dordkash@gmail.com,

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

Best Regards,

Panagiotis


Head of Community Management at cTrader