예제 #1
0
        public Trade(bool sim, int _lotDigits, string _logFileName, NQuotes.MqlApi mql4) : base(mql4)
        {
            this.logFileName = _logFileName;
            this.tradeType = TradeType.FLAT;
            this.startingBalance = mql4.AccountBalance();
            this.endingBalance = 0;
            this.lotDigits = _lotDigits;
            this.state = null;
            this.actualEntry = -1;
            this.actualClose = -1;
            this.takeProfit = 0;
            this.cancelPrice = 0;
            this.initialProfitTarget = 0;
            this.plannedEntry = 0;
            this.stopLoss = 0;
            this.originalStopLoss = 0;
            this.positionSize = 0;
            this.logSize = 0;
            this.realizedPL = 0.0;
            this.minUnrealizedPL = 0.0;
            this.maxUnrealizedPL = 0.0;
            this.spreadOrderOpen = -1;
            this.spreadOrderClose = -1;

            this.tradeOpenedDate = mql4.TimeCurrent();
            this.orderPlacedDate = new DateTime();
            this.orderFilledDate = new DateTime();
            this.tradeClosedDate = new DateTime();

            this.finalState = false;



            if (sim)
            {
                this.order = new biiuse.SimOrder(this, mql4);
                this.id = "SIM_" + mql4.Symbol() + (mql4.TimeCurrent() + TimeSpan.FromSeconds(OFFSET)).ToString();
            }
            else
            {
                this.order = new Order(this, mql4);
                this.id = mql4.Symbol() + (mql4.TimeCurrent() + TimeSpan.FromSeconds(OFFSET)).ToString();
            }

            if (!mql4.IsTesting())
            {
                string filename = mql4.Symbol() + "_" + mql4.TimeCurrent().ToString();
                int filehandle = mql4.FileOpen(filename, MqlApi.FILE_WRITE | MqlApi.FILE_READ | MqlApi.FILE_TXT);
                mql4.FileSeek(filehandle, 0, MqlApi.SEEK_END);
                string output = "****Trade: " + this.id + " ****";
                mql4.FileWriteString(filehandle, output, output.Length);
                mql4.FileWriteString(filehandle, "\n", 1);
                mql4.FileClose(filehandle);
            }
        }
예제 #2
0
 public void setState(TradeState aState)
 {
     this.state = aState;
 }