커뮤니티

ts 코드 예스 변환 관련

프로필 이미지
oceank
2017-08-16 17:44:04
225
글번호 112055
답변완료
다음과 같은 ts 이지코드를 예스에 붙여넣으면 에러가 엄청 많이 발생하네요... 도와주세요 Variables: m_typeEvalBase( 0.0 ), m_dbEvalProfitLoss( 0.0 ), m_nBarNumberBid( 0.0 ), m_nBarNumberAsk( 0.0 ), IntrabarPersist m_bValidEnvironment( false ), IntrabarPersist m_dbTickUnit( 0.0 ), m_dbTickPrice( 0.0 ), IntrabarPersist m_bSetExitRateAlwaysLong( false ), IntrabarPersist m_bSetExitRateAlwaysShort( false ), m_bExitPartLongHappend( false ), m_bExitPartShortHappend( false ), IntrabarPersist m_nTotalOpen( 1 ), IntrabarPersist m_nOpenVolume( 1 ), IntrabarPersist m_nTradeVolume( 1 ), IntrabarPersist m_nOpenAmount( 0 ), IntrabarPersist m_nTotalVolumes( 0 ), IntrabarPersist m_nTotalAmount( 0 ), IntrabarPersist m_bOrderSignaled( False ), tmpCount( 0 ), tmpAgo( 0 ), StochasticFast_Range( 14 ), StochasticFast_FastK( 3 ), StochasticFast_FastD( 3 ), outFastK( 0 ), outFastD( 0 ), outSlowK( 0 ), outSlowD( 0 ), stcst_fast( 0 ); Arrays: m_aryOpenVolume[1](0), m_aryExitVolume[1](0), m_aryOpenPrice[1](0), m_aryExitPrice[1](0); { ===================================== Get Volume from Direct Amount ===========================} Method double GetValidVolumeByDirectAmount(int amount) Var: double RetVolume; Begin if amount > Close Then RetVolume = amount / Close Else RetVolume = 0; Return RetVolume; End; { ===============================================================================================} { ===================================== Get Volume from rate of Amount ==========================} Method double GetValidVolumeByRateAmount(int amount, double rate) Var: double RetVolume; Begin if (amount * rate) > Close Then RetVolume = (amount * rate) / Close Else RetVolume = 0; Return RetVolume; End; { ===============================================================================================} { ===================================== Get Direct Volume =======================================} Method double GetValidVolumeByDirectVolume(int vol) Var: double RetVolume; Begin RetVolume = vol; Return RetVolume; End; { ===============================================================================================} { ====================================== Get Volume from rate of Volume =========================} Method double GetValidVolumeByRateVolume(int vol, double rate) Var: double RetVolume; Begin RetVolume = vol * rate * 0.01; Return RetVolume; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Open--------------------------------------------------} Method void BuyEval_ThisClose(int open_count, int vol, double price) Begin Buy ("[E]매수진입(TC)") vol Shares this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open------------------------------------------------} Method void BuyReal_ThisClose(int open_count, int vol, double price) Begin Buy ("[R]매수진입(TC)") vol Shares this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_ThisClose(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_ThisClose(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_ThisClose(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade =============================================} { --------------------------------------Open---------------------------------------------------} Method void BuyEval_NextOpen(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NO)") vol Shares next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open--------------------------------------------------} Method void BuyReal_NextOpen(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NO)") vol Shares next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextOpen(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextOpen(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextOpen(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Open--------------------------------------------------} Method void BuyEval_NextMarket(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NM)") vol Shares next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open------------------------------------------------} Method void BuyReal_NextMarket(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NM)") vol Shares next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextMarket(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextMarket(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextMarket(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Open----------------------------------------------------} Method void BuyEval_NextStop(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NS)") vol Shares next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open---------------------------------------------------} Method void BuyReal_NextStop(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NS)") vol Shares next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextStop(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextStop(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextStop(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade =============================================} { --------------------------------------Open---------------------------------------------------} Method void BuyEval_NextLimit(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NL)") vol Shares next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open--------------------------------------------------} Method void BuyReal_NextLimit(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NL)") vol Shares next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextLimit(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextLimit(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextLimit(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Exit--------------------------------------------------} Method void SellEval_ThisClose(int open_count, int vol, double price) Begin Sell ("[E]매수청산(TC)") vol Shares Total this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_ThisClose(int open_count, int vol, double price) Begin Sell ("[R]매수청산(TC)") vol Shares Total this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_ThisClose(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_ThisClose(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_ThisClose(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextOpen(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NO)") vol Shares Total next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextOpen(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NO)") vol Shares Total next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextOpen(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextOpen(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextOpen(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextMarket(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NM)") vol Shares Total next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit---------------------------------------------------} Method void SellReal_NextMarket(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NM)") vol Shares Total next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextMarket(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextMarket(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextMarket(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextStop(int open_count, int vol, double price) Begin Sell ("[E매수청산(NS)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextStop(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NS)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextStop(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextStop(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextStop(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextLimit(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NL)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextLimit(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NL)") vol Shares Total next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextLimit(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextLimit(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextLimit(open_count, vol, price); End; End; End; { ===============================================================================================} Method double GetEvalTotalProfitLoss(int eval_type) Var: double eval_rate; Begin If MarketPosition = 1 Then Begin switch (eval_type) Begin case 0: eval_rate = (Close * CurrentShares) - (AvgEntryPrice * CurrentShares); break; case 1: eval_rate = (Close - AvgEntryPrice) / AvgEntryPrice * 100.0; break; case 2: eval_rate = (Close - AvgEntryPrice) / m_dbTickUnit; break; case 3: eval_rate = Close - AvgEntryPrice; break; End; End; Return eval_rate; End; { ===============================================================================================} Method double GetEvalEntryProfitLoss(int eval_type, int ago_num) Var: double eval_rate; Begin eval_rate = 0.0; If MarketPosition = 1 AND CurrentEntries > ago_num Then Begin value1 = m_aryOpenPrice[CurrentEntries - 1 - ago_num]; If value1 <> 0 Then Begin switch (eval_type) Begin case 0: eval_rate = Close - value1; break; case 1: eval_rate = (Close - value1) / value1 * 100.0; break; case 2: eval_rate = (Close - value1) / m_dbTickUnit; break; case 3: eval_rate = Close - value1; break; End; End; End; Return eval_rate; End; { ===============================================================================================} Method bool IsOperatingTime() Var: bool ret_val; Begin ret_val = true; Return ret_val; End; { ===============================================================================================} Method bool IsTodayBar(int bar_date) Var: bool ret_val; Begin ret_val = bar_date = CurrentDate; Return ret_val; End; { ===============================================================================================} { ====================================== Open Price Method ======= =========================} Method double GetOpenPrice(int ago_num) Var: double RetPrice; Begin RetPrice = 0.0; If CurrentEntries > ago_num Then Begin RetPrice = m_aryOpenPrice[CurrentEntries - 1 - ago_num]; End; Return RetPrice; End; { ===============================================================================================} { ====================================== Exit Price Method =================================} Method double GetExitPrice(int ago_num) Var: double RetPrice; Begin RetPrice = 0.0; If CurrentEntries > ago_num Then Begin RetPrice = m_aryExitPrice[CurrentEntries - 1 - ago_num]; End; Return RetPrice; End; { ===============================================================================================} Method int GetEqualTopCount(int ago, int bar_range) Var: int RetCount; Begin RetCount = 0; tmpCount = bar_range; tmpAgo = ago; Value1 = HighestFC(High[tmpAgo], tmpCount + 1); For Value2 = 0 To tmpCount - 1 Begin If Close[Value2 + tmpAgo] = Value1 Then RetCount = RetCount + 1; End; Return RetCount; End; { ===============================================================================================} Method int GetEqualBottomCount(int ago, int bar_range) Var: int RetCount; Begin RetCount = 0; tmpCount = bar_range; tmpAgo = ago; Value1 = LowestFC(Low[tmpAgo], tmpCount + 1); For Value2 = 0 To tmpCount - 1 Begin If Close[Value2 + tmpAgo] = Value1 Then RetCount = RetCount + 1; End; Return RetCount; End; { ===============================================================================================} Once Begin ClearPrintLog; m_dbTickUnit = MinMove / PriceScale; m_dbTickPrice = MinMove / PriceScale * BigPointValue; m_bValidEnvironment = (GetAppInfo( aiApplicationType ) = cChart); MessageLog("Tick 단위 : ", m_dbTickUnit); MessageLog("Tick 가격 : ", m_dbTickPrice); MessageLog("Big Point : ", BigPointValue); MessageLog("진입수량 : ", m_nOpenVolume); End; { ===============================================================================================} { ======================================< STRATEGY CODES >=======================================} { ===============================================================================================} If m_bValidEnvironment = True Then Begin m_bOrderSignaled = false; stcst_fast = Stochastic( High, Low, Close, StochasticFast_Range, StochasticFast_FastK, StochasticFast_FastD, 1, outFastK, outFastD, outSlowK, outSlowD ); If MarketPosition = 0 AND m_bOrderSignaled = false Then Begin If outFastK Crosses Above outFastD Then Begin m_nTradeVolume = m_nOpenVolume; BuyOrder_ThisClose(CurrentEntries, m_nTradeVolume, CurrentAsk, false); m_bOrderSignaled = true; End; End; If MarketPosition = 1 AND m_bOrderSignaled = false Then Begin If outFastK Crosses Below outFastD Then Begin m_nTradeVolume = CurrentContracts; SellOrder_ThisClose(CurrentEntries, m_nTradeVolume, CurrentBid, false); m_bOrderSignaled = true; End; End; End;
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2017-08-21 18:16:09

안녕하세요 예스스탁입니다. 죄송하지만 해당 내용은 올려주신 식만으로는 내용 판독이 되지 않아 변경을 해드릴수 없습니다. EL을 사용한지 오래되어 최신버전의 함수등을 알지 못하고 능숙하지 않아 올려주신 내용에 대해 변경이 가능하지 않습니다. 구현하고자 하는 전략 내용에 대해 글로 정리해 올려주시기 바랍니다. 수식으로 단순변환은 가능하지 않을것 같습니다. 도움을 드리지 못해 죄송합니다. 즐거운 하루되세요 > oceank 님이 쓴 글입니다. > 제목 : ts 코드 예스 변환 관련 > 다음과 같은 ts 이지코드를 예스에 붙여넣으면 에러가 엄청 많이 발생하네요... 도와주세요 Variables: m_typeEvalBase( 0.0 ), m_dbEvalProfitLoss( 0.0 ), m_nBarNumberBid( 0.0 ), m_nBarNumberAsk( 0.0 ), IntrabarPersist m_bValidEnvironment( false ), IntrabarPersist m_dbTickUnit( 0.0 ), m_dbTickPrice( 0.0 ), IntrabarPersist m_bSetExitRateAlwaysLong( false ), IntrabarPersist m_bSetExitRateAlwaysShort( false ), m_bExitPartLongHappend( false ), m_bExitPartShortHappend( false ), IntrabarPersist m_nTotalOpen( 1 ), IntrabarPersist m_nOpenVolume( 1 ), IntrabarPersist m_nTradeVolume( 1 ), IntrabarPersist m_nOpenAmount( 0 ), IntrabarPersist m_nTotalVolumes( 0 ), IntrabarPersist m_nTotalAmount( 0 ), IntrabarPersist m_bOrderSignaled( False ), tmpCount( 0 ), tmpAgo( 0 ), StochasticFast_Range( 14 ), StochasticFast_FastK( 3 ), StochasticFast_FastD( 3 ), outFastK( 0 ), outFastD( 0 ), outSlowK( 0 ), outSlowD( 0 ), stcst_fast( 0 ); Arrays: m_aryOpenVolume[1](0), m_aryExitVolume[1](0), m_aryOpenPrice[1](0), m_aryExitPrice[1](0); { ===================================== Get Volume from Direct Amount ===========================} Method double GetValidVolumeByDirectAmount(int amount) Var: double RetVolume; Begin if amount > Close Then RetVolume = amount / Close Else RetVolume = 0; Return RetVolume; End; { ===============================================================================================} { ===================================== Get Volume from rate of Amount ==========================} Method double GetValidVolumeByRateAmount(int amount, double rate) Var: double RetVolume; Begin if (amount * rate) > Close Then RetVolume = (amount * rate) / Close Else RetVolume = 0; Return RetVolume; End; { ===============================================================================================} { ===================================== Get Direct Volume =======================================} Method double GetValidVolumeByDirectVolume(int vol) Var: double RetVolume; Begin RetVolume = vol; Return RetVolume; End; { ===============================================================================================} { ====================================== Get Volume from rate of Volume =========================} Method double GetValidVolumeByRateVolume(int vol, double rate) Var: double RetVolume; Begin RetVolume = vol * rate * 0.01; Return RetVolume; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Open--------------------------------------------------} Method void BuyEval_ThisClose(int open_count, int vol, double price) Begin Buy ("[E]매수진입(TC)") vol Shares this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open------------------------------------------------} Method void BuyReal_ThisClose(int open_count, int vol, double price) Begin Buy ("[R]매수진입(TC)") vol Shares this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_ThisClose(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_ThisClose(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_ThisClose(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade =============================================} { --------------------------------------Open---------------------------------------------------} Method void BuyEval_NextOpen(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NO)") vol Shares next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open--------------------------------------------------} Method void BuyReal_NextOpen(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NO)") vol Shares next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextOpen(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextOpen(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextOpen(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Open--------------------------------------------------} Method void BuyEval_NextMarket(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NM)") vol Shares next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open------------------------------------------------} Method void BuyReal_NextMarket(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NM)") vol Shares next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextMarket(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextMarket(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextMarket(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Open----------------------------------------------------} Method void BuyEval_NextStop(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NS)") vol Shares next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open---------------------------------------------------} Method void BuyReal_NextStop(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NS)") vol Shares next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextStop(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextStop(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextStop(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade =============================================} { --------------------------------------Open---------------------------------------------------} Method void BuyEval_NextLimit(int open_count, int vol, double price) Begin Buy ("[E]매수진입(NL)") vol Shares next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Open--------------------------------------------------} Method void BuyReal_NextLimit(int open_count, int vol, double price) Begin Buy ("[R]매수진입(NL)") vol Shares next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = CurrentBar; m_aryOpenPrice[open_count] = close; m_aryOpenVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Buy Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void BuyOrder_NextLimit(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin BuyReal_NextLimit(open_count, vol, price); End; End Else Begin If reverse = false Then Begin BuyEval_NextLimit(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ============================================} { --------------------------------------Exit--------------------------------------------------} Method void SellEval_ThisClose(int open_count, int vol, double price) Begin Sell ("[E]매수청산(TC)") vol Shares Total this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_ThisClose(int open_count, int vol, double price) Begin Sell ("[R]매수청산(TC)") vol Shares Total this bar on Close; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_ThisClose(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_ThisClose(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_ThisClose(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextOpen(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NO)") vol Shares Total next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextOpen(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NO)") vol Shares Total next bar at Open; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextOpen(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextOpen(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextOpen(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextMarket(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NM)") vol Shares Total next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit---------------------------------------------------} Method void SellReal_NextMarket(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NM)") vol Shares Total next bar at Market; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextMarket(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextMarket(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextMarket(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextStop(int open_count, int vol, double price) Begin Sell ("[E매수청산(NS)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextStop(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NS)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextStop(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextStop(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextStop(open_count, vol, price); End; End; End; { ===============================================================================================} { ==================================== Long Trade ==============================================} { --------------------------------------Exit----------------------------------------------------} Method void SellEval_NextLimit(int open_count, int vol, double price) Begin Sell ("[E]매수청산(NL)") vol Shares Total next bar at price Stop; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { --------------------------------------Exit----------------------------------------------------} Method void SellReal_NextLimit(int open_count, int vol, double price) Begin Sell ("[R]매수청산(NL)") vol Shares Total next bar at price Limit; If open_count <= CurrentEntries Then Begin m_nBarNumberBid = 0; m_nBarNumberAsk = 0; m_aryExitPrice[open_count] = close; m_aryExitVolume[open_count] = vol; MessageLog("[", BarDateTime.ToString(), "] Sell Vol : ", vol, ", CurrentContracts : ", CurrentContracts); End; End; { ===============================================================================================} Method void SellOrder_NextLimit(int open_count, int vol, double price, bool reverse) Begin If IsTodayBar(BarDateTime.ELDate) = true and IsOperatingTime() = true Then Begin If reverse = false Then Begin SellReal_NextLimit(open_count, vol, price); End; End Else Begin If reverse = false Then Begin SellEval_NextLimit(open_count, vol, price); End; End; End; { ===============================================================================================} Method double GetEvalTotalProfitLoss(int eval_type) Var: double eval_rate; Begin If MarketPosition = 1 Then Begin switch (eval_type) Begin case 0: eval_rate = (Close * CurrentShares) - (AvgEntryPrice * CurrentShares); break; case 1: eval_rate = (Close - AvgEntryPrice) / AvgEntryPrice * 100.0; break; case 2: eval_rate = (Close - AvgEntryPrice) / m_dbTickUnit; break; case 3: eval_rate = Close - AvgEntryPrice; break; End; End; Return eval_rate; End; { ===============================================================================================} Method double GetEvalEntryProfitLoss(int eval_type, int ago_num) Var: double eval_rate; Begin eval_rate = 0.0; If MarketPosition = 1 AND CurrentEntries > ago_num Then Begin value1 = m_aryOpenPrice[CurrentEntries - 1 - ago_num]; If value1 <> 0 Then Begin switch (eval_type) Begin case 0: eval_rate = Close - value1; break; case 1: eval_rate = (Close - value1) / value1 * 100.0; break; case 2: eval_rate = (Close - value1) / m_dbTickUnit; break; case 3: eval_rate = Close - value1; break; End; End; End; Return eval_rate; End; { ===============================================================================================} Method bool IsOperatingTime() Var: bool ret_val; Begin ret_val = true; Return ret_val; End; { ===============================================================================================} Method bool IsTodayBar(int bar_date) Var: bool ret_val; Begin ret_val = bar_date = CurrentDate; Return ret_val; End; { ===============================================================================================} { ====================================== Open Price Method ======= =========================} Method double GetOpenPrice(int ago_num) Var: double RetPrice; Begin RetPrice = 0.0; If CurrentEntries > ago_num Then Begin RetPrice = m_aryOpenPrice[CurrentEntries - 1 - ago_num]; End; Return RetPrice; End; { ===============================================================================================} { ====================================== Exit Price Method =================================} Method double GetExitPrice(int ago_num) Var: double RetPrice; Begin RetPrice = 0.0; If CurrentEntries > ago_num Then Begin RetPrice = m_aryExitPrice[CurrentEntries - 1 - ago_num]; End; Return RetPrice; End; { ===============================================================================================} Method int GetEqualTopCount(int ago, int bar_range) Var: int RetCount; Begin RetCount = 0; tmpCount = bar_range; tmpAgo = ago; Value1 = HighestFC(High[tmpAgo], tmpCount + 1); For Value2 = 0 To tmpCount - 1 Begin If Close[Value2 + tmpAgo] = Value1 Then RetCount = RetCount + 1; End; Return RetCount; End; { ===============================================================================================} Method int GetEqualBottomCount(int ago, int bar_range) Var: int RetCount; Begin RetCount = 0; tmpCount = bar_range; tmpAgo = ago; Value1 = LowestFC(Low[tmpAgo], tmpCount + 1); For Value2 = 0 To tmpCount - 1 Begin If Close[Value2 + tmpAgo] = Value1 Then RetCount = RetCount + 1; End; Return RetCount; End; { ===============================================================================================} Once Begin ClearPrintLog; m_dbTickUnit = MinMove / PriceScale; m_dbTickPrice = MinMove / PriceScale * BigPointValue; m_bValidEnvironment = (GetAppInfo( aiApplicationType ) = cChart); MessageLog("Tick 단위 : ", m_dbTickUnit); MessageLog("Tick 가격 : ", m_dbTickPrice); MessageLog("Big Point : ", BigPointValue); MessageLog("진입수량 : ", m_nOpenVolume); End; { ===============================================================================================} { ======================================< STRATEGY CODES >=======================================} { ===============================================================================================} If m_bValidEnvironment = True Then Begin m_bOrderSignaled = false; stcst_fast = Stochastic( High, Low, Close, StochasticFast_Range, StochasticFast_FastK, StochasticFast_FastD, 1, outFastK, outFastD, outSlowK, outSlowD ); If MarketPosition = 0 AND m_bOrderSignaled = false Then Begin If outFastK Crosses Above outFastD Then Begin m_nTradeVolume = m_nOpenVolume; BuyOrder_ThisClose(CurrentEntries, m_nTradeVolume, CurrentAsk, false); m_bOrderSignaled = true; End; End; If MarketPosition = 1 AND m_bOrderSignaled = false Then Begin If outFastK Crosses Below outFastD Then Begin m_nTradeVolume = CurrentContracts; SellOrder_ThisClose(CurrentEntries, m_nTradeVolume, CurrentBid, false); m_bOrderSignaled = true; End; End; End;