Skip to content

Commit

Permalink
1.0.2 Improved the code
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoCiaccio committed Oct 7, 2022
1 parent 77bd7f2 commit cb6700d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 70 deletions.
Binary file modified Trigger.algo
Binary file not shown.
28 changes: 9 additions & 19 deletions Trigger/ToWebhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Net.Http;

namespace cAlgo
{
Expand Down Expand Up @@ -104,27 +105,16 @@ public async Task<WebhookResponse> SendAsync(string post_params)

try
{

HttpClient client = new();
HttpResponseMessage responsej = await client.GetAsync(EndPoint + "?" + post_params);

Uri myuri = new Uri(EndPoint);
responsej.EnsureSuccessStatusCode();
string responseBody = await responsej.Content.ReadAsStringAsync();

string pattern = string.Format("{0}://{1}/.*", myuri.Scheme, myuri.Host);

Regex urlRegEx = new Regex(pattern);
WebPermission p = new WebPermission(NetworkAccess.Connect, urlRegEx);
p.Assert();

ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

using (WebClient wc = new WebClient())
{

wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string json_result = await Task.Run(() => wc.UploadString(myuri, post_params));

response.Response = json_result;
response.Error = 0;
return response;
}
response.Response = responseBody;
response.Error = 0;
return response;

}
catch (Exception exc)
Expand Down
23 changes: 16 additions & 7 deletions Trigger/Trigger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
using cAlgo.API;

/*
Problemi con MessageBox:
https://help.ctrader.com/ctrader-automate/guides/ui/WinForms/#introduction
*/


using cAlgo.API;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Threading;
Expand Down Expand Up @@ -38,7 +47,7 @@ public enum Logical

public const string NAME = "Trigger";

public const string VERSION = "1.0.1";
public const string VERSION = "1.0.2";

#endregion

Expand All @@ -50,7 +59,7 @@ public enum Logical
[Parameter("Check logic every", Group = "Monitoring", DefaultValue = Monitoring.Tick)]
public Monitoring MonitorAt { get; set; }

[Parameter("Reset after these bars", Group = "Monitoring", DefaultValue = 7, MinValue = 3)]
[Parameter("Reset after these bars", Group = "Monitoring", DefaultValue = 3, MinValue = 1)]
public int MonitorReset { get; set; }

[Parameter("Enabled?", Group = "First Logic", DefaultValue = false)]
Expand Down Expand Up @@ -127,7 +136,7 @@ protected override void Initialize()
if (EndPoint.Length < 1)
{

MessageBox.Show("Wrong 'EndPoint', es. 'https://api.telegram.org/bot[ YOUR TOKEN ]/sendMessage'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Windows.Forms.MessageBox.Show("Wrong 'EndPoint', es. 'https://api.telegram.org/bot[ YOUR TOKEN ]/sendMessage'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

}
Expand All @@ -136,7 +145,7 @@ protected override void Initialize()
if (PostParams.IndexOf("{0}") < 0)
{

MessageBox.Show("Wrong 'POST params', es. 'chat_id=[ @CHATID ]&text={0}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Windows.Forms.MessageBox.Show("Wrong 'POST params', es. 'chat_id=[ @CHATID ]&text={0}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

}
Expand Down Expand Up @@ -165,7 +174,7 @@ public override void Calculate(int index)

CountCandle++;

if (CountCandle % MonitorReset == 0)
if (CountCandle >= MonitorReset)
AllowToTrigger = true;

}
Expand Down Expand Up @@ -356,7 +365,7 @@ private void ToPopUp(string mex)

mex = mex.Trim();

new Thread(new ThreadStart(delegate { MessageBox.Show(mex, "BreakOut", MessageBoxButtons.OK, MessageBoxIcon.Information); })).Start();
new Thread(new ThreadStart(delegate { System.Windows.Forms.MessageBox.Show(mex, "BreakOut", MessageBoxButtons.OK, MessageBoxIcon.Information); })).Start();

}

Expand Down
61 changes: 17 additions & 44 deletions Trigger/Trigger.csproj
Original file line number Diff line number Diff line change
@@ -1,65 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<EnableDefaultItems>False</EnableDefaultItems>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup>
<LangVersion>7.2</LangVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{848F8A5A-1282-489F-A571-511CE902EF76}</ProjectGuid>
<ProjectTypeGuids>{DD87C1B2-3799-4CA2-93B6-5288EE928820};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>cAlgo</RootNamespace>
<AssemblyName>Trigger</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\API\cAlgo.API.dll</HintPath>
</Reference>
<PackageReference Include="cTrader.Automate" Version="1.*" />
</ItemGroup>
<ItemGroup>
<Compile Include="ToWebhook.cs" />
<Compile Include="Trigger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Reference Include="cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880">
<HintPath>..\..\..\..\..\..\.nuget\packages\ctrader.automate\1.0.2\lib\net6.0\cAlgo.API.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
65 changes: 65 additions & 0 deletions Trigger/Trigger.csproj.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<LangVersion>7.2</LangVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{848F8A5A-1282-489F-A571-511CE902EF76}</ProjectGuid>
<ProjectTypeGuids>{DD87C1B2-3799-4CA2-93B6-5288EE928820};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>cAlgo</RootNamespace>
<AssemblyName>Trigger</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\API\cAlgo.API.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ToWebhook.cs" />
<Compile Include="Trigger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit cb6700d

Please sign in to comment.