{"id":117,"date":"2021-01-04T10:28:23","date_gmt":"2021-01-04T10:28:23","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=117"},"modified":"2025-02-27T07:36:09","modified_gmt":"2025-02-27T07:36:09","slug":"sending-option-orders-and-exiting-option-orders-in-algomojo-platform-using-amibroker","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/sending-option-orders-and-exiting-option-orders-in-algomojo-platform-using-amibroker\/","title":{"rendered":"Sending Option Orders and Exiting Option Orders in Algomojo Platform using Amibroker"},"content":{"rendered":"\n<p>This tutorial helps you to understand the options trading module and the requirements to set up and send and exit option orders from Amibroker in a systematic way. This coding framework provides the basic foundation to entry and exit option order from Amibroker for Algomojo Trading Platform<\/p>\n\n\n\n<p><strong>Understanding PlaceFOOptionsOrder<\/strong> <strong>API<\/strong><\/p>\n\n\n\n<p>PlaceFOOptionsOrder api is used to send ATM, ITM, OTM Options Order. Currently PlaceFOOptionsOrder is supported by brokers like Aliceblue,Tradejini,Zebu &amp; Enrich.<\/p>\n\n\n\n<p>Here is the sample request and response for PlaceFOOptionsOrder<\/p>\n\n\n\n<p>For detailed information on Algomojo API&#8217;s visit the <a href=\"https:\/\/docs.algomojo.com\/docs\/api\/v1\">API Documentation <\/a>section<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">Request example :\n\n{\n    &quot;api_key&quot;:&quot;c1997d92a3bb556a67dca7d1446b70&quot;,\n    &quot;api_secret&quot;:&quot;5306433329e81ba41203653417063c&quot;,\n    &quot;data&quot;:\n      {\n        &quot;strg_name&quot;:&quot;Test Strategy&quot;,\n        &quot;s_prdt_ali&quot;:&quot;BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML&quot;,\n        &quot;Tsym&quot;:&quot;NIFTY07JAN2114000CE&quot;,\n        &quot;exch&quot;:&quot;NFO&quot;,\n        &quot;Ttranstype&quot;:&quot;B&quot;,\n        &quot;Ret&quot;:&quot;DAY&quot;,\n        &quot;prctyp&quot;:&quot;MKT&quot;,\n        &quot;qty&quot;:&quot;75&quot;,\n        &quot;discqty&quot;:&quot;0&quot;,\n        &quot;MktPro&quot;:&quot;NA&quot;,\n        &quot;Price&quot;:&quot;0&quot;,\n        &quot;TrigPrice&quot;:&quot;0&quot;,\n        &quot;Pcode&quot;:&quot;NRML&quot;,\n        &quot;AMO&quot;:&quot;NO&quot;\n      }\n}\n\nResponse example :\n\n{\n    &quot;NOrdNo&quot;: &quot;200810000277991&quot;,\n    &quot;stat&quot;: &quot;Ok&quot;\n}<\/code><\/pre>\n\n\n\n<p><strong>Option Offset Control<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"877\" height=\"466\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image.png\" alt=\"\" class=\"wp-image-118\"\/><\/figure>\n\n\n\n<p>one can use the offset to select the ATM, ITM,OTM Options.<\/p>\n\n\n\n<p>In order to make the execution logic smoother and smarter following Execution Logic is preferred for Option Order Entry and Exit. One can modify the Execution Logic to their comfort. The below logic is just a prototype.<\/p>\n\n\n\n<p>Execution Logic is coded only for<\/p>\n\n\n\n<p>1) Long Call Option Entry, <br>2) Long Put Option Entry<br>3) Exit Long Call Option (Square off Based on the Qty from Position Book)<br>4) Exit Long Put Option (Square off Based on the Qty from Position Book)<\/p>\n\n\n\n<p><strong>Execution Logic for Placing Options Order<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"615\" height=\"686\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image-1.png\" alt=\"\" class=\"wp-image-119\"\/><\/figure>\n\n\n\n<p><strong>Execution Logic for Exiting Options Order<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"628\" height=\"688\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image-2.png\" alt=\"\" class=\"wp-image-120\"\/><\/figure>\n\n\n\n<p><strong>Setting up the Options Test Execution AFL File<\/strong><\/p>\n\n\n\n<p><strong>1<\/strong>)Copy the AFL under the name <strong>Algomojo Options Test Module.afl<\/strong> and keep it under Amibroker\\Formulas\\Algomojo folder<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">#include &lt; algomojooptions.afl &gt;\n\n\n_SECTION_BEGIN(&quot;Algomojo Options Test Module&quot;);\n\ntrigger = ParamTrigger(&quot;Place Option Order&quot;,&quot;PRESS&quot;);\nlongcall = ParamTrigger(&quot;Place Long Call Order&quot;,&quot;PRESS&quot;);\nlongput = ParamTrigger(&quot;Place Long Put Order&quot;,&quot;PRESS&quot;);\nexitcall = ParamTrigger(&quot;Exit Call&quot;,&quot;PRESS&quot;);\nexitput = ParamTrigger(&quot;Exit Put&quot;,&quot;PRESS&quot;);\n\nspot_sym = ParamStr(&quot;spot_sym&quot;,&quot;NIFTY&quot;); \/\/Enter the symbol name here\nexpiry_dt = ParamStr(&quot;expiry_dt&quot;, &quot;28JAN21&quot;);\nstrike_int = ParamStr(&quot;strike_int&quot;,&quot;50&quot;);\nTtranstype = ParamList(&quot;Transaction Type&quot;,&quot;B|S&quot;);\nopt_type = ParamList(&quot;opt_type&quot;,&quot;CE|PE&quot;,0);\noffset = ParamStr(&quot;Offset&quot;,&quot;0&quot;); \/\/No. of strikes away from ATM Strike\nEnableAlgo = ParamList(&quot;Algo Mode&quot;,&quot;Disable|Enable&quot;,0); \/\/ Algo Mode\n\nstatic_name_ = Name()+GetChartID()+interval(2)+stgy_name;\nstatic_name_algo = Name()+GetChartID()+interval(2)+stgy_name+&quot;algostatus&quot;;\n\/\/StaticVarSet(static_name_algo, -1); \nGfxSelectFont( &quot;BOOK ANTIQUA&quot;, 14, 100 );\nGfxSetBkMode( 1 );\nif(EnableAlgo == &quot;Enable&quot;)\n{\nSetChartBkColor(ColorBlend(colorGrey40,colorBlack));\nAlgoStatus = &quot;Algo Enabled&quot;;\nGfxSetTextColor( colorGreen ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=1)\n{\n_TRACE(&quot;Algo Status : Enabled&quot;);\nStaticVarSet(static_name_algo, 1);\n}\n}\nif(EnableAlgo == &quot;Disable&quot;)\n{\nAlgoStatus = &quot;Algo Disabled&quot;;\nGfxSetTextColor( colorRed ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=0)\n{\n_TRACE(&quot;Algo Status : Disabled&quot;);\nStaticVarSet(static_name_algo, 0);\n}\n}\n\nif(EnableAlgo == &quot;Enable&quot;){\n\nif (trigger) \n{\n\/\/Place Options Order\norderresponse = placeoptionorder(spot_sym,expiry_dt,strike_int,Ttranstype,opt_type,offset);\n_TRACEF(&quot;\\nExecuted Symbol :&quot;+orderresponse);\n}\n\n\nif (longcall) \n{\n\/\/Place Options Order\norderresponse = placeoptionorder(spot_sym,expiry_dt,strike_int,&quot;B&quot;,&quot;CE&quot;,offset);\n_TRACEF(&quot;\\nExecuted Symbol :&quot;+orderresponse);\n}\n\n\nif (longput) \n{\n\/\/Place Options Order\norderresponse = placeoptionorder(spot_sym,expiry_dt,strike_int,&quot;B&quot;,&quot;PE&quot;,offset);\n_TRACEF(&quot;\\nExecuted Symbol :&quot;+orderresponse);\n}\n\nif (Exitcall) \n{\n\/\/Place Options Order\nsqoffstatus = squareoffoptions(&quot;CE&quot;);\n_TRACEF(&quot;\\nExit Call Response :&quot;+sqoffstatus);\n}\n\n\nif (ExitPut) \n{\nsqoffstatus = squareoffoptions(&quot;PE&quot;);\n_TRACEF(&quot;\\nExit Put Response :&quot;+sqoffstatus);\n}\n\n}\n\n\n_SECTION_END();\n\n\n_SECTION_BEGIN(&quot;Price&quot;);\n\nSetChartOptions(0,chartShowArrows|chartShowDates);\n_N(Title = StrFormat(&quot;{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}&quot;, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));\nPlot( C, &quot;Close&quot;, ParamColor(&quot;Color&quot;, colorDefault ), styleNoTitle | ParamStyle(&quot;Style&quot;) | GetPriceStyle() ); \n\n_SECTION_END();\n<\/code><\/pre>\n\n\n\n<p><strong>2)<\/strong>Copy the AFL under the name <strong>algomojooptions.afl<\/strong> under the path Amibroker\\formulas\\include folder<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/Multi Broker Amibroker Option Execution Module\n\/\/Coded by Algomojo\n\/\/Date : 30\/12\/2020\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n\n\n\/\/Use this code only for Single Legged Long Only Options and Exiting Long Only Options\n\n\n_SECTION_BEGIN(&quot;Algomojo Options&quot;);\n\n\nuid = ParamStr(&quot;Client ID&quot;,&quot;TS2499&quot;);\nuser_apikey = ParamStr(&quot;user_apikey&quot;,&quot;86cbef19e7e61ccee91e497690d5814e&quot;); \/\/Enter your API key here\napi_secret = ParamStr(&quot;api_secret&quot;,&quot;4a94db82ea4fa140afaa2f039efffd18&quot;); \/\/Enter your API secret key here\ns_prdt_ali = &quot;BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML&quot;;\nprctyp = ParamList(&quot;prctyp&quot;,&quot;MKT|L|SL|SL-M&quot;,0);\nPcode = ParamList(&quot;Pcode&quot;,&quot;NRML|CO|MIS&quot;,2);\nPrice = ParamList(&quot;Price&quot;,&quot;0&quot;);\nTrigPrice = ParamList(&quot;TrigPrice&quot;,&quot;0&quot;);\nqty = Param(&quot;Quatity&quot;,75,0,100000,1); \nstgy_name = ParamStr(&quot;Strategy Name&quot;, &quot;Options&quot;);\nbroker = ParamStr(&quot;Broker&quot;,&quot;tj&quot;); \/\/Broker Short Code - ab - aliceblue, tj - tradejini, zb - zebu, en - enrich\nver = ParamStr(&quot;API Version&quot;,&quot;1.0&quot;);\nfpath = ParamStr(&quot;Symbol Filepath&quot;, &quot;C:\\\\Program Files (x86)\\\\AmiBroker\\\\Formulas\\\\Algomojo\\\\&quot;);\ntimer = 3; \/\/3 seconds for providing delay after placing order\n\nRequestTimedRefresh(1,False);\n\n\nfunction getnestorderno(response)\n{\n\nNOrdNo = &quot;&quot;;\n\n\nif(StrFind(response,&quot;NOrdNo&quot;)) \/\/Matches the orderstatus\n{\nNOrdNo = StrTrim( response, &quot;{\\&quot;NOrdNo\\&quot;:&quot; );\nNOrdNo = StrTrim( NOrdNo, &quot;\\&quot;,\\&quot;stat\\&quot;:\\&quot;Ok\\&quot;}&quot; );\n}\n\nreturn NOrdNo;\n}\n\nfunction getorderhistory(orderno)\n{\n\nalgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\napi_data = &quot;{\\&quot;uid\\&quot;:\\&quot;&quot;+uid+&quot;\\&quot;,\\&quot;NOrdNo\\&quot;:\\&quot;&quot;+orderno+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;}&quot;;\nresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;OrderHistory&quot;,api_data,broker,ver);\n\nreturn resp;\n\n\n}\n\n\nfunction getsymbol(orderno)\n{\n\nordresp = getorderhistory(orderno);\n\ndata = &quot;&quot;;\nTrsym=&quot;&quot;;\n\nfor( item = 0; ( sym = StrExtract( ordresp, item,&#039;{&#039; )) != &quot;&quot;; item++ )\n{\n\nsym = StrTrim(sym,&quot; &quot;); \/\/Trim Whitespaces\n\n\n\n\nif(StrFind(sym,&quot;complete&quot;) OR StrFind(sym,&quot;rejected&quot;)) \/\/Matches the orderstatus\n{\n\nflag = 1; \/\/turn on the flag\n\ndata = sym;\n\nfor( jitem = 0; ( ohistory = StrExtract( data, jitem,&#039;,&#039; )) != &quot;&quot;; jitem++ )\n{\n\nif(Strfind(ohistory,&quot;Trsym&quot;))\n  {\n   Trsym = StrExtract(ohistory,1,&#039;:&#039;);\n   Trsym = StrTrim(Trsym,&quot;\\&quot;&quot;);\n   \n  }\n\n}\n\n}\n\n}\n\nreturn Trsym;\n\n}\n\nfunction getorderstatus(orderno)\n{\norderstatus=&quot;&quot;;\nordresp = getorderhistory(orderno);\n\ndata = &quot;&quot;;\n\nfor( item = 0; ( sym = StrExtract( ordresp, item,&#039;{&#039; )) != &quot;&quot;; item++ )\n{\n\nsym = StrTrim(sym,&quot; &quot;); \/\/Trim Whitespaces\n\n\nif(StrFind(sym,&quot;complete&quot;) OR StrFind(sym,&quot;rejected&quot;)) \/\/Matches the orderstatus\n{\n\nflag = 1; \/\/turn on the flag\n\ndata = sym;\n\nfor( jitem = 0; ( ohistory = StrExtract( data, jitem,&#039;,&#039; )) != &quot;&quot;; jitem++ )\n{\n\nif(Strfind(ohistory,&quot;Status&quot;))\n  {\n   orderstatus = StrExtract(ohistory,1,&#039;:&#039;);\n   orderstatus = StrTrim(orderstatus,&quot;\\&quot;&quot;);\n   \n  }\n\n}\n\n}\n\n}\n\nreturn orderstatus;\n}\/\/end function\n\n\nfunction gettoken(symbol)\n{\nstoken=&quot;&quot;;\nalgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\napi_data = &quot;{\\&quot;s\\&quot;:\\&quot;&quot;+symbol+&quot;\\&quot;}&quot;;\nresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;fetchsymbol&quot;,api_data,broker,ver);\n\nfor( item = 0; ( sym = StrExtract( resp, item,&#039;{&#039; )) != &quot;&quot;; item++ )\n{\n\nsym = StrTrim(sym,&quot; &quot;); \/\/Trim Whitespaces\n\ndata = sym;\n\nfor( jitem = 0; ( ofetch = StrExtract( data, jitem,&#039;,&#039; )) != &quot;&quot;; jitem++ )\n{\n\nif(Strfind(ofetch,&quot;symbol_token&quot;))\n  {\n   stoken = StrExtract(ofetch,1,&#039;:&#039;);\n   stoken = StrTrim(stoken,&quot;\\&quot;&quot;);\n   \n  }\n\n}\n\n}\nreturn stoken;\n}\n\nfunction writetofile(filepath,ordno,symbol,ostatus)\n{\n    result =0;\n\tif(ostatus==&quot;complete&quot; OR ostatus==&quot;rejected&quot;)\n\t{\n    fh = fopen( filepath, &quot;w&quot;); \/\/Filepath of csv file with symbols\n\tif(fh)\n    {\n\t\t\n\t\tfputs(ordno + &quot;,&quot;, fh);\n\t\tfputs(symbol + &quot;,&quot;, fh);\n\t\tfputs(ostatus+&quot;,&quot;, fh);\n\t\tfclose(fh);\n\t\tresult =1;\n    } \n    }\n    \n    return result; \n}\n\nfunction placeoptionorder(spot_sym,expiry_dt,strike_int,Ttranstype,opt,off)\n{\n\nalgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\napi_data = &quot;{\\&quot;strg_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;spot_sym\\&quot;:\\&quot;&quot;+spot_sym+&quot;\\&quot;,\\&quot;expiry_dt\\&quot;:\\&quot;&quot;+expiry_dt+&quot;\\&quot;,\\&quot;opt_type\\&quot;:\\&quot;&quot;+opt+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+Ttranstype+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+qty+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+Price+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+TrigPrice+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;strike_int\\&quot;:\\&quot;&quot;+strike_int+&quot;\\&quot;,\\&quot;offset\\&quot;:\\&quot;&quot;+off+&quot;\\&quot;}&quot;;\nresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;PlaceFOOptionsOrder&quot;,api_data,broker,ver);\n\n\/\/Get Nest Order Number\nnestorderno = getnestorderno(resp);\n_TRACE(&quot;\\nNest Order No : &quot;+nestorderno);\n\ntradetime=GetPerformanceCounter()\/1000; \n\nwhile ((GetPerformanceCounter()\/1000 - tradetime) &lt; timer)\n{            \n\n\/\/Get Trading Symbol\nTsym = getsymbol(nestorderno);\n}\n_TRACE(&quot;\\nTrading Symbol : &quot;+Tsym);\n\n\/\/Get Order Status\norderstatus = getorderstatus(nestorderno);\n_TRACE(&quot;\\nOrder Status : &quot;+orderstatus);\n\/\/Get Token Number\n\/\/token = gettoken(Tsym);\n\/\/_TRACE(&quot;\\nSymbol Token : &quot;+token);\nif(opt==&quot;CE&quot;)\n{\npath = fpath+&quot;AlgomojoCE.csv&quot;;\n}\nif(opt==&quot;PE&quot;)\n{\npath = fpath+&quot;AlgomojoPE.csv&quot;;\n}\n\nwritestatus = writetofile(path,nestorderno,Tsym,orderstatus);\n_TRACEF(WriteIf(writestatus,&quot;\\nWriting to File - Success&quot;,&quot;\\nWriting to File - Failure&quot;));\n\/\/resp = resp+&quot;\\nNest Order No : &quot;+nestorderno+&quot;\\nTrading Symbol : &quot;+Tsym+&quot;\\nOrder Status : &quot;+orderstatus+&quot;\\nSymbol Token : &quot;+token;\nreturn Tsym;\n\n}\n\n\nfunction getquantity(Tsym)\n{\n\nalgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\napi_data =&quot;{\\&quot;uid\\&quot;:\\&quot;&quot;+uid+&quot;\\&quot;,\\&quot;actid\\&quot;:\\&quot;&quot;+uid+&quot;\\&quot;,\\&quot;type\\&quot;:\\&quot;&quot;+&quot;DAY&quot;+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;}&quot;;\nresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;PositionBook&quot;,api_data,broker,ver);\n\n\/\/Initialization\nflag = 0;\npossym = &quot;&quot;;\nposNetqty =0;\n\n\nfor( item = 0; ( sym = StrExtract( resp, item,&#039;{&#039; )) != &quot;&quot;; item++ )\n{\n\nsym = StrTrim(sym,&quot; &quot;);\nTsym = StrTrim(Tsym,&quot; &quot;);\n\nif(Strfind(sym,Tsym) AND StrFind(sym,Pcode)) \/\/Matches the symbol and \/\/Matches the Order Type\n{\n\nflag = 1; \/\/turn on the flag\n\ndata = sym;\n\n_TRACE(&quot; Position Book  : &quot; +data);\n\nfor( jitem = 0; ( posdetails = StrExtract( data, jitem,&#039;,&#039; )) != &quot;&quot;; jitem++ )\n{\n\n  if(Strfind(posdetails,&quot;Netqty&quot;))\n  {\n   posdetails = StrExtract(posdetails,1,&#039;:&#039;);\n   posNetqty = StrToNum(StrTrim(posdetails,&quot;\\&quot;&quot;));\n   _TRACE(&quot;\\nNetQty : &quot;+posNetqty);\n  }\n  \n\n} \/\/end of for loop\n}\n\n}\/\/end of for loop\n\nif(flag==0)\n{\n_TRACE(&quot;\\nTrading Symbol Not Found&quot;);\n}\n\nreturn posNetqty;\n\n}\n\n\nfunction squareoffoptions(opt)\n{\n\nordno = &quot;&quot;;\nSymbol = &quot;&quot;;\nostatus =&quot;&quot;;\n\n\tif(opt==&quot;CE&quot;)\n\t{\n\tfpath = fpath+&quot;AlgomojoCE.csv&quot;;\n\t}\n\tif(opt==&quot;PE&quot;)\n\t{\n\tfpath = fpath+&quot;AlgomojoPE.csv&quot;;\n\t}\n\t\n\tfh = fopen(fpath, &quot;r&quot;); \n\tif(fh)\n\t{\n\t\t\n\t\tread = fgets(fh);\n\t\tordno = StrTrim(StrExtract(read,0),&quot; &quot;);\n\t\tSymbol = StrTrim(StrExtract(read,1),&quot; &quot;);\n\t\tostatus = StrTrim(StrExtract(read,2),&quot; &quot;);\n\t\t\t\t\t\n\t\tfclose(fh);\n\t}\n\t\n\texitqty = getquantity(Symbol);\n\t_TRACE(&quot;Net Quantity in the OrderBook for the Symbol : &quot;+Symbol+&quot; is : &quot;+exitqty);\n\t\n\tif(ostatus==&quot;complete&quot; AND exitqty!=0)\n\t{\n\talgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\n\tapi_data = &quot;{\\&quot;strg_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;,\\&quot;Tsym\\&quot;:\\&quot;&quot;+Symbol+&quot;\\&quot;,\\&quot;exch\\&quot;:\\&quot;&quot;+&quot;NFO&quot;+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+&quot;S&quot;+&quot;\\&quot;,\\&quot;Ret\\&quot;:\\&quot;&quot;+&quot;DAY&quot;+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+exitqty+&quot;\\&quot;,\\&quot;discqty\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;MktPro\\&quot;:\\&quot;&quot;+&quot;NA&quot;+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;AMO\\&quot;:\\&quot;&quot;+&quot;NO&quot;+&quot;\\&quot;}&quot;;\n\tresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;PlaceOrder&quot;,api_data,broker,ver);\n\t\/\/Get Nest Order Number\n\tnestorderno = getnestorderno(resp);\n\t_TRACE(&quot;\\nNest Order No : &quot;+nestorderno);\n\n\ttradetime=GetPerformanceCounter()\/1000; \n\n\twhile ((GetPerformanceCounter()\/1000 - tradetime) &lt; timer)\n\t{            \n\n\t\/\/Get Trading Symbol\n\tTsym = getsymbol(nestorderno);\n\t}\n\t_TRACE(&quot;\\nTrading Symbol : &quot;+Tsym);\n\n\t\/\/Get Order Status\n\torderstatus = getorderstatus(nestorderno);\n\t_TRACE(&quot;\\nOrder Status : &quot;+orderstatus);\n\t\n\t}\n\telse\n\t{\n\t\n\tresp = &quot;Not Squared Off. Prev Signal Status Not in Completed State&quot;;\n\t\n\t}\n\t\n\treturn resp;\n}\n_SECTION_END();\n<\/code><\/pre>\n\n\n\n<p>3)Apply the <strong>Algomojo Options Test Module.afl<\/strong> on the Charts<\/p>\n\n\n\n<p>4)Now right click over the charts and set the Client ID, user_apikey, api_secretkey and set the required quantity<\/p>\n\n\n\n<p>5)Ensure the <strong>Symbol File Path Exists<\/strong>. This is the path where the executed symbols CE and PE Options will get saved in a CSV file for later squareoff.<\/p>\n\n\n\n<p>AlgomojoCE.csv and AlgomojoPE.csv will be saved separately only if the execution status is in <strong>complete <\/strong>mode. If the order is rejected then the file will not be saved with an executed symbol.<\/p>\n\n\n\n<p>6)<strong>Enable<\/strong> the Algo Mode<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"462\" height=\"718\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image-3.png\" alt=\"\" class=\"wp-image-121\"\/><\/figure>\n\n\n\n<p><strong>Aliceblue Monthly Option Expiry Settings<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"464\" height=\"718\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image-4.png\" alt=\"\" class=\"wp-image-122\"\/><\/figure>\n\n\n\n<p><strong>Aliceblue Weekly Option Expiry Settings<\/strong><\/p>\n\n\n\n<p>And If in case you are using Aliceblue Weekly Options then you have to use YYMDD format<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"459\" height=\"717\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/01\/image-5.png\" alt=\"\" class=\"wp-image-123\"\/><\/figure>\n\n\n\n<p>Now you can send Long Call and Long Put Orders from the press of the button from the properties box and also exit the positions by pressing the Exit Call and Exit Put Buttons which will eventually squareoff the positions based on current open positions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial helps you to understand the options trading module and the requirements to set up and send and exit option orders from Amibroker in a systematic way. This coding framework provides the basic foundation to entry and exit option order from Amibroker for Algomojo Trading Platform<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[6,15],"tags":[36,13,7,44,69],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/117"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":6,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions\/1586"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}