1. 首页
  2. 易语言 - EasyLanguage
  3. 用布尔值调试代码的方法 A Method to Debug your code by boolean

用布尔值调试代码的方法 A Method to Debug your code by boolean

What every Coder needs to make progress is the ability to generate Statistics.

  • What is any variable value at any given moment.
  • When did the variable assume a value.
  • When did an error message occur. What Line? Which Bar? etc.

By trapping Variables as they are populated your coding skills will make quantum leaps of progress.

To do this one needs to develop a coding style, a method that all your coding efforts will be approached from,
so that trapping errors or conditions line by line will be effortless.

Naming Conventions

Make the Code Yours 

One needs to develop Naming Conventions in which if your were to look any of your code in the middle of a script anywhere you could identify repetitive events because you made the coding structure yours. 

Coding Structure:
If you add a debug method to your code -leave it there. Just turn it on or off by Boolean or by one comment.
This mainly requires getting used to seeing the extra code when you are not using it.
But the time though it will save trapping an event or unexpected exception will be invaluable in the long run.

One Method to debug code

Using the EasyLanguage Output Bar (ELOB)  CTRL+SHIFT+E

EL Indicator Debugger Template Code 

At the top of each script or each piece of code I add the following – without exception

The following code identifies the Indicator/ or Strategies name
and sets Boolean conditions that turn “the debugger on or off”,
so that if you are happy with your code you just turn the debugger code off by commenting the call to the debug function at the bottom of the code.

* Require the attached Debug function to be added to your indicator/ Strategy 

//put this at the top of your code

VAR: IM(Text);  IM = ("your indicator name here,"  +numtostr(d,0)+","+numtostr(t,0)+","+GetSymbolName+":"+numtostr(Barinterval,0)+",");
VAR: ok(False),Okp(False); // Leave False this converted to true by Date Time function call at the bottom of the code below.... 

Definition:
IM  or “I am” will now be populated with your Indicator name, Date,Time,Symbol and Bar Interval of the event so that you know which Indicator and chart may have generated the stat 

Use OKP after each condition to do the following:  

It will trigger the Debug function (attached) to print  =ONLY A DAYS WORTH= of stats

place this code below your condition
if okP then print(IM, “my condition”, YourVariables);
 

Use the OK only to print a select_  or_ unique debugging question for ONE BAR only

place this code below your condition
If ok then print (IM,”Trade Test:”,Variable1 ,” “, Variable2,” “, Variable3); // etc…
 

//at the bottom of your code place -easier to find…   change date and time as needed or just comment to turn off
 
OkP = debug( 1060420   ,  925    ,ok,okp); //Note the Date and time structure

Synopsis of the structure of the code needed
other than the function attached to debug to the Easy Language Output bar… edit code where necessary

VAR:IM(Text); IM= ("your indicator name here,"  +numtostr(d,0)+","+numtostr(t,0)+","+GetSymbolName+":"+numtostr(Barinterval,0)+",");
VAR:ok(False),Okp(False); // Leave False this converted to true by Date Time function call at the bottom of the code below....If okP then print(IM, "my condition", Your variable);// days worth of Stats
If ok then print (IM,"Trade Test:",Trade[1] , trade); // one bars worht of stats
OkP = debug( 1060420   ,  925    ,ok,okp); 
更新于 2020年6月3日

这篇文章对您有帮助吗?

相关的话题

留言评论