cbot issue with execute order once everytime condition activates

Created at 05 Jan 2019, 20:39
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!
MI

missyeam

Joined 05.01.2019

cbot issue with execute order once everytime condition activates
05 Jan 2019, 20:39


Please how do i execute an order once everytime the condition is met

ive used eg if positions.count==1 etc. but it ends up executing all the time.

how do i automate one trade per conditions been met like at tradingview


@missyeam
Replies

PanagiotisCharalampous
07 Jan 2019, 09:41

Hi missyeam,

Thanks for posting in our forum. You can use a flag. See an example below.

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.AlaskanStandardTime, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {

        bool _orderExecuted;
        bool _conditionMet;
        protected override void OnStart()
        {

        }

        protected override void OnBar()
        {
            //Set your condition
            // _conditionMet = ...
            if (!_orderExecuted && _conditionMet)
            {
                _orderExecuted = true;
                //Execute your trading
            }

        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

ryanoia@gmail.com
31 Jul 2019, 16:15

I tried incorporating the above in one of my cbots and an error occurred showing this:

 

Error CS0649: Field 'cAlgo.Robots.BlueMethDemoExpiration._conditionMet' is never assigned to, and will always have its default value false

 

I guess the part where you wrote" _conditionMet = ..." means something and needs to be applied to the condition. However, I am not certain how. Assistance with a more specific sample would be highly appreciated.


@ryanoia@gmail.com