你好
我有以下代碼,試圖通過計算當前柱的Close-Low來製作MA。我的主要問題是:
當我第一次放置室內時,它被畫得很好。但在它之後它開始畫一條直線......不能真正找出原因。
我已經知道這個錯誤是我得到的兩個while循環的原因,它與蠟燭變量有關。如果我將歷史變量替換while循環中的蠟燭變量,那麼它可以正常工作,但通過這樣做,它將一次又一次地重新繪製所有條形圖。
任何想法/建議?
這是代碼
插入的代碼#include lt; stderror.mqhgt; #include lt; stdlib.mqhgt; #property indior_level1 0 #property indior_separate_window/#property indior_chart_window/Indior在主窗口中繪製#property indior_buffers 2 #property indior_color1白色//#property indior_color2藍色//---緩衝區雙Buf_0#91;#93 ;;/--- parameters extern int history = 3000; extern bool log_on = false; extern int MAperiod = 14;/extern bool separate_window = true; string build = ver 0.29g-TEST-MA; bool isHistoryLoading; int lastperiod = 0; int init(){isHistoryLoading = true; SetIndexStyle(0,DRAW_LINE,DRAW_SECTION,2); SetIndexBuffer(0,Buf_0); SetIndexLabel(0,MA); IndiorShortName(MA( MAperiod ) build); SetLevelValue(0,0.0000);/水平線水平設置為return(0); } int deinit(){return(0); } int start(){double ARM = 0,barARM = 0,ASB = 0;雙O,C,H,L; datetime dt,mdt,dt1,dtTemp; int i,j,k,candles,counted_bars;/int btbars = backtest_bars; double Buffer#91; 10000#93 ;; if(isHistoryLoading){dt = iTime(Symbol(),PERIOD_M1,0); if(dt == 0){isHistoryLoading = true; return;} isHistoryLoading = false; counted_bars = 0; } else counts_bars = IndiorCounted(); if(candleslt; 0)返回(0);蠟燭=棒材 - counted_bars;/第一個不計數的索引(candlesgt; history-1)//如果太多吧... {candles = history-1;/..計算指定數量}/*********************************主循環**** ************************ while((ilt; =蠟燭)){L =低#91;我#93 ;; C =關閉#91 ; I#93 ;; ARM = ARM C-L; wlog(我改變了我#91; i #93;);緩衝區#91; i#93; = ARM;/在單獨的窗口wlog上繪製indior(緩衝區#91; i #93; = Buf_0#91; i#93;);我 ; ARM = 0; }/END年int vi = 0; double sum = 0.0; while(vilt; =蠟燭)//CALCULATE MA {vi ; for(int vk = vi; vklt; vi MAperiod; vk ){sum = sum Buffer#91; vk#93 ;; }/for sum = sumMAperiod; Buf_0#91; vi#93; = sum;/;總和= 0; }/while return(0); } void wlog(string s){if(log_on){Print(s); }}