Help place i need deloper system

Created at 19 Aug 2016, 13:12
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!
TA

tang_to_444@hotmail.com

Joined 26.04.2016

Help place i need deloper system
19 Aug 2016, 13:12


 

https://www.youtube.com/watch?v=YHyFaYBdZcI

i code not work 

how i can fix? 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
//เขียน ea เชิ่งกลยุทธ์โดยออกแบบเป็นแนว heging statigy
//https://www.youtube.com/watch?v=YHyFaYBdZcI 
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestHed : Robot
    {
        /*
        [Parameter("Ma", DefaultValue = 10)]
        public int ma01 { get; set; }
                                      */
        [Parameter("TP", DefaultValue = 10)]
        public double tp { get; set; }

        [Parameter("batp+", DefaultValue = 0)]
        public double batp { get; set; }

        [Parameter("St lost", DefaultValue = 0.01)]
        public double Quantity { get; set; }

        [Parameter("step Lost", DefaultValue = 1)]
        public int steplost { get; set; }

        [Parameter("Step", DefaultValue = 10)]
        public double step { get; set; }


        //ส่วนของการนำค่าเข้าและเก็บข้อมูลการเปิด ปิด order

        public int x = 0;
        public int frist = 0;


        protected override void OnStart()
        {
            Positions.Opened += dataopen;
            Positions.Closed += dataclose;




        }
        protected override void OnTick()
        {
           
            var psbuy = Positions.Find("hbuy", Symbol, TradeType.Buy);
            if (psbuy == null)
            {
                // sendorder(1);
                exorder(1);
            }
            else { 
            
            }
           
            

        }
        public void dataopen(PositionOpenedEventArgs arg)
        {
            var ps = arg.Position;
            int positioncou = Positions.Count;
            x++;
            Print("   " + x);
            /*
            if (frist == 1) {
                //order แรกเป็น buy
                if (x % 2 == 0)
                {
                    noslbuy();
                }
                else
                {
                    noslsell();
                }
            }
            else
            {
                if (x % 2 == 0)
                {
                    noslsell();
                }
                else
                {
                    noslbuy();
                }
            } */
            if (ps.TradeType == TradeType.Buy)
            {
                ModifyPosition(ps, null, ps.EntryPrice + 10 * Symbol.PipSize);
                Print("TP" + ps.TakeProfit);
                PlaceStopOrder(TradeType.Sell, Symbol, 1000 * (positioncou + steplost), ps.EntryPrice - (step * Symbol.PipSize), "hsell", null, null);
                
            }     

            if (ps.TradeType == TradeType.Sell)
            {
                ModifyPosition(ps, null, ps.EntryPrice - 10 * Symbol.PipSize);
                Print("TP" + ps.TakeProfit);
                PlaceStopOrder(TradeType.Buy, Symbol, 1000 * (positioncou + steplost), ps.EntryPrice + (step * Symbol.PipSize), "hbuy", null, null);
            }
            
        }
        //ปลด tp sl buy
        public void noslbuy()
        {
            var psbuy = Positions.FindAll("hbuy", Symbol, TradeType.Buy);
            if (psbuy != null) { 
            foreach (var hebuy in psbuy)
            {
                ModifyPosition(hebuy, null, null);
            }            
            }
        }
        //ปลด tp sl sell
        public void noslsell()
        {
            
            var pshell = Positions.FindAll("hsell", Symbol, TradeType.Sell);
            if (pshell != null) { 
            foreach (var hesell in pshell)
            {
                ModifyPosition(hesell, null, null);
            }  }
           

        }
        //อีเว้น การปิด order
        public void dataclose(PositionClosedEventArgs arg)
        {
          
        }
        //ฟังชั่นการส่ง order
        public void exorder(int order)
        {
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);
            if (order == 1)
            {
                var buydata = ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "hbuy", null, null);
                if (buydata.IsSuccessful)
                    x = 1;
                frist = 1;
                return;
            }
            else if (order == 2)
            {
                var selldata = ExecuteMarketOrder(TradeType.Sell, Symbol, volumeInUnits, "hsell", null, null);
                if (selldata.IsSuccessful)
                    x = 1;
                frist = 2;
                return;
            }
        }

        public void closeall()
        {
            var hebuy = Positions.FindAll("hbuy", Symbol, TradeType.Buy);
            var hesell = Positions.FindAll("hsell", Symbol, TradeType.Sell);
            Print("data " + (Account.Equity - Account.Balance));
            
                foreach (var phb in hebuy)
                {
                    ClosePosition(phb);
                }
                foreach (var phs in hesell)
                {
                    ClosePosition(phs);
                }
                foreach (var pdo in PendingOrders)
                {
                    CancelPendingOrder(pdo);
                }
            

        }

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



    }
}


 


@tang_to_444@hotmail.com
Replies

... Deleted by UFO ...

tang_to_444@hotmail.com
29 Aug 2016, 05:36 ( Updated at: 21 Dec 2023, 09:20 )

Not work 

buy 0.01

pading sell 0.04

if open sell 0.04  position buy0.01 close 

i need open sell 0.04 win step pip and position buy close 

 


@tang_to_444@hotmail.com