var TLib = addLibrary("TradingLibrary.efsLib"); // Global variable let Obj = Object.assign({}, TLib.CreateTradeTrackingObject()); // Global variable function preMain(){ setPriceStudy(true); setStudyTitle("TradeLibrarySyntaxInMain"); } function main(){ if(getBarState() == BARSTATE_ALLBARS){ Obj.sProgramName = "YourProgram'sName"; Obj.bPrintTrades = true; // When troubleshooting code you can turn off the printout of trades. Obj.bBackTestOn = true; // Instead of true, you could have a parameter in main to toggle this true/false. Obj.bAlertsOn = true; // Instead of true, you could have a parameter in main to toggle this true/false. } if (!Obj.bInit && isLastBarOnChart()) Obj.bInit = true; if(getBarState() == BARSTATE_NEWBAR) Obj.bOkToTrade = true; // false = NO trades if it's used as shown below! if(!Obj.bAmLong && Obj.bOkToTrade){ // && ...Set conditions to go Long if(Obj.bAmShort) TLib.CoverShort(Obj, close(0), false, false); TLib.GoLongLimit(Obj, close(0), true); // bPlayAlert == true here, false above...so only 1 alert } if(!Obj.bAmShort && Obj.bOkToTrade){ // && ...Set conditions to go Short if(Obj.bAmLong) TLib.SellLong(Obj, close(0), false, false); TLib.GoShortLimit(Obj, close(0), true); // bPlayAlert == true here, false above...so only 1 alert } if(Obj.bPrintHeader && isLastBarOnChart()){ // Prints the trades header after the program loads TLib.PrintHeader(Obj.sProgramName); Obj.bPrintHeader = false; } return; } function PrintStreamingTrades(){ // Put a button on your chart to print streamed trades. TLib.PrintTradesArray(Obj); } function PrintObjValues(){ // Put a button on your chart to print the global object's current values for troubleshooting. TLib.PrintObjectValues(Obj); }